Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
sakshamjain
Advisor
Advisor

Introduction


SAP Process Automation (SAP PA) is a powerful tool that allows organizations to automate their business processes, increase efficiency, and reduce manual effort. One common task in SAP PA is downloading files from the SAP system or the Web. While seemingly straightforward, there are certain best practices and considerations to keep in mind to ensure a smooth and effective file download process. In this blog, we will explore the right way to download a file in SAP Process Automation.

The file that we will be downloading is saved within the SAP BTP Document Management Service.

How to Download a File



 

Step 1: Create a variable to hold the name of the folder where your file resides in DMS, Leave it empty if the file is in the root folder.

Step 2: Create a variable to hold the name of the file you want to download.

Step 3: Create a variable to hold the ClientID.

Step 4: Create a variable to hold the ClientSecret

Step 5: Use the Encode String Activity to encode the ClientID and ClientSecret in base64 format.


Step 6: To access the DMS (Document Management Service) system and download the file, it is necessary to acquire authorization. In this stage, we will utilize the Customer Script Activity to set up configurations for calling the Auth Service, enabling us to obtain the necessary authorization.



var authRequestOptions = {
    method: 'GET',
    responseType: 'json',
    headers: {
        'Accept': 'application/json',
        'Authorization': 'Basic '+ base64EncodedUsernamePassword,
        'Content-Type': 'application/json'
    },
    'resolveBodyOnly': true
};

return authRequestOptions;

Step 7: Now we’ll call the Auth Service using the Call Web Service with Destination Activity which will provide us with an authentication token.


Step 8: In this step, we’ll again use Customer Script Activity to set up configurations to Download the File.



var requestParams = {
    url: folderName ? folderName + '/' + uploadedFileName : uploadedFileName,
    method: 'GET',
    headers: {
        'Authorization': 'Bearer ' +authToken,
    },
    resolveBodyOnly: true,
    responseType: 'buffer'
};

return requestParams;

Step 9: Finally, we will employ the Download File Activity to carry out the actual downloading of the file from the DMS (Document Management Service). Subsequently, we will save the downloaded file in our system.



Conclusion


Downloading files using SAP Process Automation (SPA) can be a straightforward and efficient process if you follow the right steps. By understanding the download requirements, utilizing the appropriate SPA activities, and ensuring proper authentication and authorization, you can achieve successful file downloads with ease.
3 Comments
rui_jin
Product and Topic Expert
Product and Topic Expert
0 Kudos
HI Jain,

 

Could you please let me know what happens under the hood when setting "responseType"? I'm trying to replicate exactly same work in SAP CAP. I would like SDM return me a buffer like what automation did. Does "responseType" help the request setting some headers? or basically what happened when we ask it to return us a buffer.

 

Thanks

Rui
Jana_dK
Participant
0 Kudos
Hi,

 

interesting blog, thank you for that! Have you also already tried saving a file coming from the attachment API in S4?

 

Kind regards

Jana
0 Kudos
Hi,
It's possible to implement the same app in PHP?
At the moment I have the DOKNR, DOKAR, DOKTL, DOKVR, FILENAME and the server where the files are storaged, my goal is generate the URL to download it, it's that possible, all in PHP?

Regards,
Fernando