mPower™ Blog Series

Seamless File Upload and Download to SAP using SAP NetWeaver Gateway

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.

Figure 1

Figure 1: Import Parameters

Figure 2

Figure 2: Export Parameters

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.

Figure 3

Figure 3: Import Parameters

Figure 4

Figure 4: Export Parameters

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.  

Figure 5

Figure 5: Replicate Entity Structure

b. Map the services for query operation for module: /INVMWL/FM_WI_ATTACH_DISPLAY

Figure 6

Figure 6: Map the Services

2.  Replicate the entity structure and map the services to download the data.

a. Replicate the fields in the Properties screen.

Figure 7

Figure 7: Replicate the entity structure to read the data

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.

Figure 8

Figure 8: Map the services to download the data

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 to sales@innovapptive.com

Share this post

Leave a comment

Your email address will not be published.