Skip to Content
Author's profile photo Arun Chembra

Gateway Service using the OData Channel Approach (ABAP Coding) for Media Links(Photo,Document)

Introduction

This document will help you  to Implement a Gateway Service using the OData Channel approach (ABAP Coding)  for Media Links. Gateway Service is implemented by creating two ABAP classes – Model Provider class and Runtime Data Provider class. In this document, i will cover the creation of the Model Provider class and a Runtime Data Provider class.


Prerequisites:

1.     Gateway IWBEP system: IW_BEP 200 SP5 and above

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


Step 1 : Goto Transaction SE80

IMG1.png

Step 2 : Create Model Provider Class ZCL_TEST_MPC

IMG2.png

Step 3 : Save Model Provider Class in local object

IMG3.png

Step4 : Goto Model Provider Class click on Properties Tab and assign superclass /IWBEP/CL_MGW_PUSH_ABS_MODEL as shown below.

IMG4.png

Step 5 : Go to methods and redefine the method called DEFINE.

IMG5.png

method DEFINE.

data:
lo_annotation        
type ref to /iwbep/if_mgw_odata_annotation,
lo_data_object       
type ref to /iwbep/if_mgw_odata_entity_typ,
lo_model_object      
type ref to /iwbep/if_mgw_odata_entity_typ,
lo_model_entity_type 
type ref to /iwbep/if_mgw_odata_entity_typ,
lo_entity_set        
type ref to /iwbep/if_mgw_odata_entity_set,
lo_complex_type      
type ref to /iwbep/if_mgw_odata_cmplx_type,
lo_association       
type ref to /iwbep/if_mgw_odata_assoc,
lo_complex_type2     
type ref to /iwbep/if_mgw_odata_cmplx_type,
lo_association2      
type ref to /iwbep/if_mgw_odata_assoc,
lo_nav_property      
type ref to /iwbep/if_mgw_odata_nav_prop,
lo_property          
type ref to /iwbep/if_mgw_odata_property,
lo_action            
type ref to /iwbep/if_mgw_odata_action,
lo_parameter         
type ref to /iwbep/if_mgw_odata_parameter,
lo_ref_constraint    
type ref to /iwbep/if_mgw_odata_ref_constr.

super->define( ).

* carrier object gets defined
lo_data_object
= model->create_entity_type( ‘IMAGE’ ).
lo_property
= lo_data_object->create_property( ‘EMPLOYEE_ID’ ).
lo_property
->set_is_key( ).
lo_property
->set_filterable( abap_true ).
lo_data_object
->create_property( ‘MIME_CODE’ ).
lo_property
= lo_data_object->create_property( ‘CONTENT’ ).
lo_property
= lo_data_object->create_property( ‘URL’ ).

lo_data_object->bind_structure( ‘ZEMP_DOCUMENT’ ).

* setting a data object as media type means that it gets a special semantic by having a url and allows streaming etc.
lo_data_object
->set_is_media( ).
 

endmethod.

Step 6 : Create Model Provider Class ZCL_TEST_DPC

IMG6.png

Step 7 : Goto Model Provider Class click on Properties Tab and assign superclass  /IWBEP/CL_MGW_PUSH_ABS_DATA as shown below.

IMG7.png

Step 8 : Redefine method GET_STREAM and paste the below code and replace the function module ‘ZHR_DOCUMENT’ with your function module which will give binary data. Or directly pass binary data to ls_stream-value without function module.

IMG8.png

method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM.

data: ls_stream    type         ty_s_media_resource,
lo_api   
type ref to  if_mr_api,
er_entity
type ref to data,
lr_entity
type ref to data,
l_photo
type xstring,
i_pernr
type  persno.

READ TABLE it_key_tab WITH KEY name = ‘EMPLOYEE_ID’ INTO ls_key_tab.

IF sysubrc = 0.
MOVE ls_key_tab-value TO i_pernr.

ENDIF.


call function ‘ZHR_DOCUMENT’
exporting
i_pernr
= i_pernr
importing
pdf_doc
= l_photo.

ls_stream-value = l_photo.

copy_data_to_ref( exporting is_data = ls_stream
changing  cr_data = er_stream ).

endmethod.

Step 9 : Goto Transaction SPRO Maintain Models and  Click Create button

IMG9.png

IMG10.png

Step 10  : Enter the Model Provider Class name as shown below

IMG11.png

Step 11  : Goto Transaction SPRO Maintain Services and  Click Create button

IMG12.png

IMG13.png

Step 12  : Enter the Model Provider Class name as shown below, Assign Model and save.

IMG14.png

Step 13  : Activate the Service in Gateway System

IMG15.png

IMG16.png


http://XXXXXXXXXXXXXXXXXXXXXXX:9000/sap/opu/odata/sap/ZTES_SERVICE/$metadata

IMG17.png

To read the Media Link( Photo,Document) we need to add suffix /$value to the GetEntity(Read)

  URL  as shown below.

http://XXXXXXXXXXXXXXXX:9000/sap/opu/odata/sap/ZTES_SERVICE/IMAGECollection(‘12345678’)/$value

Assigned tags

      25 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Arnab Das
      Arnab Das

      thanks Arun

      Author's profile photo Former Member
      Former Member

      Nice document....

      Author's profile photo Syam Babu
      Syam Babu

      Excellent Blog Arun.

      Author's profile photo Arun Chembra
      Arun Chembra
      Blog Post Author

      Thanks Syam....

      Author's profile photo Former Member
      Former Member

      good one...

      Author's profile photo Arun Chembra
      Arun Chembra
      Blog Post Author

      Thanks...

      Author's profile photo Former Member
      Former Member

      Thanks Arun - your blog helped me develop my upload/download service. I did it using SEGW instead of ABAP coding - it might help others wanting to use that approach How To Upload and Download Files Using SAP NW Gateway SP06

      Author's profile photo Former Member
      Former Member

      thanks a lot. very very helpful.

      Author's profile photo Arun Chembra
      Arun Chembra
      Blog Post Author

      Thanks pinaki...

      Author's profile photo Former Member
      Former Member

      Hi Arun,

      In the simialr way, i created zfunction module with

      input

      employee number, sequence number

      output

      payslip  in xstring format

      pdf_fsize as i.

      now i need to show this xstring output in odata services.

      step1:

      i created project in segw transaction .

      can you help me how to incorporate after that..

      Author's profile photo Arun Chembra
      Arun Chembra
      Blog Post Author

      Hi Vijay,

      You have to redefine the GET_STREAM class and you have to call your function module inside this method as shown below. Please let me know if you face any issue.

      method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM.

      data: ls_stream    type         ty_s_media_resource,
      lo_api   
      type ref to  if_mr_api,
      er_entity
      type ref to data,
      lr_entity
      type ref to data,
      l_photo
      type xstring,
      i_pernr
      type  persno.

      READ TABLE it_key_tab WITH KEY name = 'EMPLOYEE_ID’ INTO ls_key_tab.

      IF sy-subrc = 0.
      MOVE ls_key_tab-value TO i_pernr.

      ENDIF.


      call function 'ZHR_DOCUMENT'
      exporting
      i_pernr
      = i_pernr
      importing
      pdf_doc
      = l_photo.

      ls_stream-value = l_photo.

      copy_data_to_ref( exporting is_data = ls_stream
      changing  cr_data = er_stream ).

      endmethod.

      Author's profile photo Arun Chembra
      Arun Chembra
      Blog Post Author
      Author's profile photo Former Member
      Former Member

      Thanks Arun.. that is done..

      i don't have any problem with get_stream method as of now, but when i am trying to generate runtime artifacts of get_entity it is saying like zcl_zxx_dpc was generated with syntax error.

      i just created one custom RFC similar to bapi_get_payslip_pdf and imported to get_entity and there after i am getting this error.

      Thanks,

      Vijay

      Author's profile photo Former Member
      Former Member

      Nice Blog Arun.

      Author's profile photo Former Member
      Former Member

      Pramila, this article is somewhat out-of-date if you are above SP3 (who wouldn't be? 😉 ). While it is useful to know how to do this, Service Builder does the work of building the MPC and DPC in a few seconds instead of minutes (perhaps hours if you mess up the MPC define).

      Author's profile photo Former Member
      Former Member

      Hi Chembra,

      Thanks for your document...

      Author's profile photo Former Member
      Former Member

      HI,

      How can we upload those file in MIME repository ?

      My requirement is ==>

      I have upload file in SAP-UI5, those file should upload in MIME repository (SAP-ECC)back end.

      How can i do this? 

      I have referred below link (which is shown  Gateway connection details).

      http://scn.sap.com/community/netweaver-gateway/blog/2013/08/14/how-to-upload-and-download-files-using-sap-nw-gateway#comment-470346

      Kindly help me on this...

      Author's profile photo Arun Chembra
      Arun Chembra
      Blog Post Author

      HI ,

      You can pass data as binary format along with the MIME code , Once you received the same in SAP you have to call the corresponding function module or you have to write the logic to insert binary data to the MIME repository.

      Thanks,

      Arun

      Author's profile photo Former Member
      Former Member

      Hi Arun,

      I have created below screen for PDF! upload in SAP-UI5.

      Below code I have written in SAP gateway system.

       

      * Get MIME repository information

      lr_mime_rep = cl_mime_repository_api=>if_mr_api~get_api( ).

      * Upload FILE into MIME repository.

      lr_mime_rep->put(

         EXPORTING

           i_url                     = p_path

           i_content                 = lv_content

         EXCEPTIONS

           parameter_missing         = 1

           error_occured             = 2

           cancelled                 = 3

           permission_failure        = 4

           data_inconsistency        = 5

           new_loio_already_exists   = 6

           is_folder                 = 7

           OTHERS                    = 8 ).

      Back end system required file name with extension and XSTRING(Converted PDF data).

      How to convert  PDF file into XSTRING or BINARY in SAP-UI5?




      Author's profile photo Syam Babu
      Syam Babu

      Hi Akshath,

      SAP UI5 is not released any Lib files for XSTRING to PDF.

      Please check below link for your clarification.

      http://scn.sap.com/community/developer-center/front-end/blog/2014/02/03/display-smartform-pdf-in-sapui5

      Thanks,

      Syam

      Author's profile photo rajeesh o
      rajeesh o

      plz check below link it is awesome

      File Upload/Download through NetWeaver Gateway

      Author's profile photo Pavan Golesar
      Pavan Golesar

      Classic post, Thank you, Indeed helpful.

      -Pavan Golesar

      Author's profile photo Deepak Tewari
      Deepak Tewari

      Hi Arun,

      Thanks for such a useful post.

      It served two of my pusposes: Defining Dynamic Entities and Uploading media files in OData.

      I have a doubt in a statement

      lo_data_object->bind_structure( ‘ZEMP_DOCUMENT’ ).

      What is the need of this statement?

      I found that if I don't use it, my service's metadata is not loaded and I am unable to use that.

      Please help me out 🙂

       

      Author's profile photo Arun Chembra
      Arun Chembra
      Blog Post Author

      Hi Deepak,

      This is used to bind your final structure.

      Its very old method, now the binding and will take care by the SEGW gateway service builder.

      Thanks & regards,

      Arun

       

      Author's profile photo Deepak Tewari
      Deepak Tewari

      Hi Arun,

       

      Thanks a lot for your reply.

      But what if I have a requirement in which I dont know about the structure which my entity is going to have.

      In simpler words: I want to have a dynamic entity in which the fields should change at runtime.

      Is there any work around for this ?

       

      Regards

      Deepak