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
Step 2 : Create Model Provider Class ZCL_TEST_MPC
Step 3 : Save Model Provider Class in local object
Step4 : Goto Model Provider Class click on Properties Tab and assign superclass /IWBEP/CL_MGW_PUSH_ABS_MODEL as shown below.
Step 5 : Go to methods and redefine the method called DEFINE.
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
Step 7 : Goto Model Provider Class click on Properties Tab and assign superclass /IWBEP/CL_MGW_PUSH_ABS_DATA as shown below.
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.
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.
Step 9 : Goto Transaction SPRO Maintain Models and Click Create button
Step 10 : Enter the Model Provider Class name as shown below
Step 11 : Goto Transaction SPRO Maintain Services and Click Create button
Step 12 : Enter the Model Provider Class name as shown below, Assign Model and save.
Step 13 : Activate the Service in Gateway System
http://XXXXXXXXXXXXXXXXXXXXXXX:9000/sap/opu/odata/sap/ZTES_SERVICE/$metadata
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |