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

To report this post you need to login first.

22 Comments

You must be Logged on to comment or reply to a post.

      1. Vijay Vegesana

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

        (0) 
        1. Arun Chembra 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 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.

          (0) 
          1. Vijay Vegesana

            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

            (0) 
    1. Ron Sargeant

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

      (0) 
    1. Arun Chembra 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

      (0) 
      1. akshath lt

        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?




        (0) 

Leave a Reply