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
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
thanks Arun
Nice document....
Excellent Blog Arun.
Thanks Syam....
good one...
Thanks...
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
thanks a lot. very very helpful.
Thanks pinaki...
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..
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.
Hi Vijay,
Check this blog also : http://scn.sap.com/community/netweaver-gateway/blog/2013/08/14/how-to-upload-and-download-files-using-sap-nw-gateway
Thanks,
Arun Chembra
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
Nice Blog Arun.
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).
Hi Chembra,
Thanks for your document...
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...
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
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?
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
plz check below link it is awesome
File Upload/Download through NetWeaver Gateway
Classic post, Thank you, Indeed helpful.
-Pavan Golesar
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
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 🙂
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
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