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: 
RashmiBR
Employee
Employee


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

































EmployeeData EmployeePhoto
EmpID(k) EmpID(k)
Lastname ContentType
Firstname Uri
Title -
MaritalStatus -


____________________________________________________________________________________________________________________________

Prerequisites:

  1. Gateway IWBEP system: IW_BEP 200 SP5 and above

  2. Gateway IWFND system: IW_FND 250(Gateway HUB) SP3

  3. 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. BAPI_EMPLOYEE_GETDATA: To get the Employee Data.

  2. HRWPC_RFC_EP_READ_PHOTO_URI: To get URI of the photo of an Employee uploaded in the SAP Business Suite system.

  3. 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 :-

  1. Tx code: SEGW



   2.  Set the annotation ‘Media’ of ‘EmployeePhoto’  entity

MediaLink.JPG


   3.  Generate the Runtime Artifacts using the tool bar button or the

        Generate Runtime Context Menu option on Project node.

        The Runtime Artifacts get generated successfully with the message  on the status bar.


  4.   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.



    • 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:

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.


 

42 Comments