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, let’s see a use case here....
__________________________________________________________________________________________________________
Use Case:
Let’s 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
____________________________________________________________________________________________________________________________
Prerequisites:
- 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.
- 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.
_____________________________________________________________________________________________________________
Let’s take this ahead with a step by step approach :-
- Tx code: SEGW
2. Set the annotation ‘Media’ of ‘EmployeePhoto’ entity
for example:
The above URL would fetch the EmployeeData with EmpID = 00100276
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.
8.
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'
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.