Technical Articles
Send PDF with oData & Media Handling in the oData
Hello ABAPPERS,
Today’s topic is very interesting . The aim is send Adobeform pdf with oData, also we can send Smartform as well. This is very easy thing for implementation. I will explain details step by step.
Prerequests
-Knowledge about adobeform or smartform
-Basic knowledge about oData
-SAP Gateway usage
First of all, We create an Adobeform and a structure for using in the odata.
Then we can create gateway service from our structure.
In the section of entity types, We must choose the our entity as ‘Media’.
Then we will go to the Data Provider class and redefine the get_stream method inside the folder ‘/IWBEP/IF_MGW_APPL_SRV_RUNTIME’
Then we will call the pdf to get RAWSTRING data. After that we give the RAWSTRING data to the ‘er_stream -value’ and give the mimetype as ‘application/pdf’ to display pdf data. Also we can send different files as well like jpeg .
"fill ls_general_data for adobe import str
TRY.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = 'zadobe'
IMPORTING
e_funcname = lv_formname.
CATCH cx_fp_api_repository.
CATCH cx_fp_api_usage.
CATCH cx_fp_api_internal.
ENDTRY.
"it is important to give the getpdf variable abap_true
"to get rawstring inside the pdf
ls_output_param-getpdf = abap_true.
ls_output_param-dest = COND #(
WHEN ls_defaults-spld IS NOT INITIAL
THEN ls_defaults-spld
ELSE 'LP01' ).
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = ls_output_param
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION lv_formname
EXPORTING
/1bcdwb/docparams = ls_doc_param
is_general = ls_general_data
IMPORTING
/1bcdwb/formoutput = ls_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'FP_JOB_CLOSE'
IMPORTING
e_result = ls_result
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
"to change er_stream varriable.
ls_stream-value = ls_formoutput-pdf.
ls_stream-mime_type = 'application/pdf'.
copy_data_to_ref(
EXPORTING
is_data = ls_stream
CHANGING
cr_data = er_stream ).
As a result we can send pdf files with oData. You can check in the SAP Gateway Client.
Lastly , Also you can check this blog .
Don’t hesitate to ask a question and share your comments please 😊
Best Regards!
-Uğur İlhan
hi Uğur ilhan,
it was very helpful article . can you share the data type of str zui_odata_s001 or str. details.
Thanks,
Ajit Singh
Hi Ajit,
I don't have the information about that structure at the moment. But i think that is not the point, this is classical structures which we used.
Best Regards,
Ugur
It´s work fine but you need declare LS_STREAM
TYPES: BEGIN OF ty_stream,
mime_type TYPE string,
value TYPE xstring,
END OF ty_stream.
DATA: ls_stream TYPE ty_stream.
Thats it!!
Thanks !! Very helpful article