You are on page 1of 7

How to Read Photo from SAP system using SAP NetWeaver Gateway

Posted by Rashmi BR
inShare4

in SAP NetWeaver Gateway on 22-Feb-2013 16:39:20

Consider a scenario where we need to read (1) a Business Object entry and also (2) an associated attachment (document, photo or video) uploaded in the SAP Business Suite system. Requirement(1) can be achieved by generating an OData service using Service Builder(SB) In this blog, we shall focus on the implementation of requirement(2) and we make use of the extensibility feature of SB. Reading of an attachment in OData world is in the form of a byte stream also called Media Links. Though not directly supported by SB, it has a provision to enable the same via an annotation called Media at the EntityType level. For easy understanding, lets see a use case here.... ______________________________________________________________________________ ____________________________

Use Case:
Lets consider a scenario where an Employee photo has to be read in addition to Employee details from SAP Business Suite system using SAP NetWeaver Gateway. Entities: EmployeeData and EmployeePhoto EmployeeData
EmpID(k) Lastname Firstname Title MaritalStatus

EmployeePhoto
EmpID(k) ContentType Uri
-

________________________________________________________________________________________________________ ____________________

Prerequisites:
1. 2. 3.

Gateway IWBEP system: IW_BEP 200 SP5 and above Gateway IWFND system: IW_FND 250(Gateway HUB) SP3 A suitable HCM SAP Business Suite System Design Employee model with both the entities having default entity-sets created, linked via a bidirectional association having cardinality 1:1. Following sample BAPIs have been used in this blog.

1. 2. 3.

BAPI_EMPLOYEE_GETDATA: To get the Employee Data. HRWPC_RFC_EP_READ_PHOTO_URI: To get URI of the photo of an Employee uploaded in the SAP Business Suite system. PAD_PHOTO_UPDATE_GET_DETAIL: To get byte stream of the Employee's photo to be rendered. Please ensure these/equivalent BAPIs/BORs are available in the SAP Business Suite system that will be used in your implementation. ______________________________________________________________________________ _______________________________ Lets take this ahead with a step by step approach :-

1.

Tx code: SEGW Create a Gateway project: ZMEDIALNK_SB Import the designed metadata file using File Import functionality 2. Set the annotation Media of EmployeePhoto entity

o o

3. Generate the Runtime Artifacts using the tool bar button Generate Runtime Context Menu option on Project node. The Runtime Artifacts get generated successfully with the message on the status bar.
4.

or the

Redefine the DEFINE method of Extended Model Provider class ZCL_ZMEDIALNK_SB_MPC_EXT .

Select the method and click on Redefine button as shown in the above screen shot. Double click on the method to open the editor. Copy and Paste the Code snippet from this link. Click on Save and Activate the class. 5. Go to Service Implementation folder. Expand the EmployeeDataSet node and select GetEntity(Read). Right click and select the option Map to Data Source.
o

Here we should use an RFC/BOR to get the Personal Data of EmployeeData record for example: BAPI_EMPLOYEE_GETDATA

Mapping: Drag and drop EMPLOYEE_ID of the Data Source(DS) Parameters to EmpID property of the Entity Set. To map the other properties, expand the Table Type PERSONAL_DATA[] and drag-drop the DS parameter to the corresponding Entity Set properties as shown in the screen shot below.

6. Go to Service Implementation folder. On similar lines, expand the EmployeePhotoSet node and select GetEntity(Read). Right click and select the option Map to Data Source. Here we should use an RFC/BOR to get the Uri and ContentType of EmployeePhoto record for example: HRWPC_RFC_EP_READ_PHOTO_URI

7. Generate the Runtime Artifacts. Mapping DS in step 5 and 6 results in generation of Data Provider implementations of GetEntity (Read) for EmployeeData and EmployeePhoto entitysets. This enables reading EmployeeData and EmployeePhoto records. for example:

http://server/sap/opu/odata/sap/ZMEDIALNK_SB_SRV/EmployeeDataSet('00100276')?$format=xml

The above URL would fetch the EmployeeData with EmpID = 00100276

http://server/sap/opu/odata/sap/ZMEDIALINK_SB_SRV/EmployeePhotoSet('00100276')?$format=xml

The above URL would fetch the EmployeePhoto with EmpID = 00100276

Here Uri depicts the link to the SAP Business Suite System repository where the media/photo actually resides. This bring us to the final step of rendering the EmployeePhoto via the IWBEP system. To achieve this we need to use a BAPI/BOR which can take EmpID as input and return the byte stream of the photo. In our example we use the BAPI 'PAD_PHOTO_UPDATE_GET_DETAIL'
8.

Here we need to redefine the /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM method of the

Extended Data Provider Class ZCL_ZMEDIALNK_SB_DPC_EXT.

On similar lines of redefintion of DEFINE method in Extended Model Provider Class, here the /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM method of Extended Data Provider class needs to be redefined.

Double click on the method to open the editor. Copy and paste the code snippet found here. Click on Save and Activate the class. Now the SAP NetWeaver Gateway service generated and extended for our Business requirement in this SB Project is ready for consumption. To read the media link, Employee photo in our case, we need to suffix /$value to the GetEntity(Read) URL of EmployeePhoto i.e.,

http://server/sap/opu/odata/sap/ZMEDIALINK_SB_SRV/EmployeePhotoSet('00100276')/$value
And we are DONE!!! Hope this makes Reading Media Links via SB easier for you.

You might also like