Thursday, 2 September 2021

How to download the Content repository (Archive link/Open Text attachments) to App Server or Desktop using ABAP code

Note – This is an example from SAP S/4 HANA – 1809 system but not restricted to a particular release.

Introduction – The SAP Content Server is a stand-alone component in which a large quantity of electronic documents of any format and with any content can be stored. The SAP applications concerned must support the use of the SAP Content Server. The documents can be saved either in one or more MaxDB instances or in the file system. The SAP Content Server is available for Windows 2000 & 2003 Server as well as for several UNIX variants.

The content repository configuration is maintained via T code OAC0. Please see below example for Accounts Payable (Please note, this article doesn’t focus on the Content repository configuration).

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

Business Requirement : There are cases when the attachments need to be downloaded from one content server and moved to a different server. For a mass migration of all the attachments , we can get help from server admins and network teams but if we just need to download a select number of attachments (based on attachment types e.g. PDF/JPG or business area e.g. AP/GL/Vendors etc.) writing an ABAP code can be faster and more flexible (e.g. renaming the attachments based on business requirements). Please refer to below technical details:

SAP Table TOA01 stores the details of all the Archive Link attachments.

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

A typical entry in the table for Accounts Payable looks like below:

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

The object ID is combination of: COMPANY CODE + DOCUMENT NUMBER + FISCAL YEAR.

Step 1. Use FM: SCMS_DOC_INFO to get the CMS information of the document:

CREP_ID = TOA01-ARCHIV_ID

DOC_ID = TOA01-ARC_DOC_ID

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

If you see the pop-up below, hit SPACE button and hit ENTER again.

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

CMS info is returned in the COMPS table:

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

COMP_ID (in this case ‘data’) returned by the FM is important to proceed to next step.

If the file is PDF or an image (.JPG/.BMP etc.), then COMP_ID is returned as data. If the file is TXT, then COMP_ID is returned as note.

Step 2: Call FM: SCMS_HTTP_GET_FILE with below parameters:

CREP_ID = TOA01-ARCHIV_ID

DOC_ID = TOA01-ARC_DOC_ID

COMP_ID = Value returned above from FM: SCMS_DOC_INFO

PATH = Desktop of app server location, in case of desktop (frontend = X)

Access mode = R (read)

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

System validates the HTTP connection. If connection is successful, transfer is initiated:

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

Allow the file download. Download is successful:

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

File is available on desktop:

ABAP Development, SAP ABAP Tutorial and Materials, SAP ABAP Career, SAP ABAP Study Materials, SAP ABAP Guides, SAP ABAP Certification

No comments:

Post a Comment