Introduction
SAP NetWeaver Gateway is a technology that offers a seamless platform to connect devices, environments and platforms. It enables creation of cutting edge solutions with world class UX providing the potential of SAP business software into new experiences including social and collaboration environments, mobile, tablet and rich internet applications. It offers the flexibility to use any programming language or model to connect with SAP applications by leveraging REST services and OData/ATOM protocols, eliminating the necessity to have the knowledge of SAP.
This blog provides step by step instructions of how you can leverage Innovapptive’s function modules to upload files for any document and later download the files to SAP server, appreciating the technology behind this approach. Before we get into the actual process of file upload/download process, let’s get a brief technical background of the function modules behind the upload/download process.
There are two function modules on the SAP server to enable the file upload/download process:
1. /INVMWL/FM_WI_ATTACH_DISPLAY (Display Attachments – file upload): In this module, you can define the input parameters (IM_OBJKEY and IM_APPID) to get the required attachments for that file.
2. /INVMWL/FM_WI_ATTACH_DOWNLOAD (Download Attachments – file download): Once you get the required attachments, the next step is to fetch the data from the attachments. This is accomplished in this module, wherein you can define 3 parameters (IM_APPID, IM_OBJKEY and IM_OBJID) to retrieve the information available in each of the attachments.
Let’s assume, there is a sales order for which you need to attach multiple files. Technically speaking, here sales order is referred by the object key and respective files that you want to attach are referred by its respective object ids. Note that each document can have a one reference id. First, let’s understand the high level steps for the file upload/download process:
File Display
STEP 1 – TASKS TO PERFORM ON SAP BACK-END SERVER
1. Pass the parameter names (IM_OBJKEY and IM_APPID) to get the attachments.
2. Read the information in the documents and convert into binary code.
STEP 2 – TASKS TO PERFORM IN RFC (SAP NETWEAVER GATEWAY) FOR
1. Replicate the entity structure (as defined /INVMWL/FM_WI_ATTACH_DISPLAY module) and map the services to get the list of attachments.
2. Replicate the entity structure (as defined in /INVMWL/FM_WI_ATTACH_DOWNLOAD module) and map the services to download the data. Now, let’s move on to the high level steps:
File Upload and Download
STEP 1 – TASKS TO PERFORM ON SAP BACK-END SERVER
1. Get the attachments for the file (refer figure 2) by passing the input parameters. For this, follow the below logic:
a. Based on the parameters (Object key & Appid) that you pass, select the business object.
b. Call the functional module BDS_ALL_CONNECTIONS_GET with the following parameters:
Input for this functional module
Classname = Business Object
Classtype = BO
Objkey = IM_OBJKEY
Output for this functional module
Number of attachments’ component ids
c. Loop the component ids.
d. Call the functional module:SO_DOCUMENT_READ_API1
e. Enter the component id to get data from each of the attached documents.
Note: If there are multiple attachments, multiple object ids gets retrieved for a single object key (Ex: Sales Order)
f. Endloop.
2. Read and convert the information in the files to binary code (Refer figure 4),
a. Call the function module SO_DOCUMENT_READ_API1.
b. Get the attached document data in string format.
c. Call the functional module SCMS_BINARY_TO_XSTRING to convert to xstring from binary.
STEP 2 – TASKS TO PERFORM IN RFC (SAP NETWEAVER GATEWAY) FOR
1. Replicate the entity structure using RFC module and map the services to get the list of attachments.
a. Create the entity structure in the Properties screen. This generates a URL.
b. Map the services for query operation for module: /INVMWL/FM_WI_ATTACH_DISPLAY
2. Replicate the entity structure and map the services to download the data.
a. Replicate the fields in the Properties screen.
b. Map the services (Operation GetEntity) in the /INVMWL/FM_WI_ATTACH_DOWNLOAD module, which generates a URL where you can view/download the data of the attachments.
Contact us today to learn how you can leverage our custom mobile development accelerators to reduce your app development times by over 50%. Read more here – Custom Application Development. Contact us by sending an email tosales@innovapptive.com