Display Smartform as Pdf in Sap Odata for SAPUI5
How to Create Smartforms as Pdf, please see the following steps :
Goto SEGW Tcode : Create Project. Then Create Entity Type and Entity Set
SoPrint Entity
SoPrintSet entittyset of automatic created.
Generate the runtime artifacts and redefine the DEFINE method in MPC_EXT
The following code here :
METHOD define.
DATA: lo_property TYPE REF TO /iwbep/if_mgw_odata_property,
lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ.
super->define( ).
lo_entity_type = model->get_entity_type(
iv_entity_name = 'SoPrint').
IF lo_entity_type IS BOUND.
lo_property = lo_entity_type->get_property('Kunnr').
lo_property->set_as_content_type( ).
ENDIF.
ENDMETHOD.
Create a Smartform
Screenshot is given below :
Code in DPC_EXT
write code in the following method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM
METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.
DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
ls_stream TYPE ty_s_media_resource,
lv_so_id TYPE kunnr.
DATA: lv_fname TYPE rs38l_fnam,
ls_control_parameters TYPE ssfctrlop,
ls_output_options TYPE ssfcompop,
lv_device_type TYPE rspoptype,
bin_pdfx TYPE xstring,
ls_otf_data TYPE ssfcrescl.
DATA:lt_otf TYPE STANDARD TABLE OF itcoo,
lt_lines TYPE STANDARD TABLE OF tline,
t_otf_from_fm TYPE ssfcrescl.
READ TABLE it_key_tab INTO ls_key_tab WITH KEY name = 'Kunnr'.
lv_so_id = ls_key_tab-value.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZODATA'
IMPORTING
fm_name = lv_fname.
ls_output_options-tddest = 'LOCL'.
ls_output_options-xdfcmode = abap_true.
ls_output_options-xsfcmode = abap_true.
ls_output_options-tdnewid = abap_true.
ls_output_options-tdimmed = abap_true.
ls_control_parameters-no_dialog = abap_true.
ls_control_parameters-preview = space.
ls_control_parameters-getotf = abap_true.
CALL FUNCTION lv_fname
EXPORTING
control_parameters = ls_control_parameters
output_options = ls_output_options
IMPORTING
job_output_info = t_otf_from_fm
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
others= 5.
* Pass otf data to otf table
lt_otf[] = t_otf_from_fm-otfdata[].
*?Convert?OTF?to?xString
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_file = bin_pdfx
TABLES
otf = lt_otf
lines = lt_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
ls_stream-value = bin_pdfx.
ls_stream-mime_type = 'application/pdf'.
* Copy?data?to?reference
copy_data_to_ref(
EXPORTING is_data = ls_stream
CHANGING cr_data = er_stream ).
ENDMETHOD.
Finally Generate the Runtime Object.
In the end, we can show results. In a frontend fiori gateway, run /n/IWFND/GW_CLIENT.
Goto SEGW Tcode : Create Project. Then Create Entity Type and Entity Set
SoPrint Entity
SoPrintSet entittyset of automatic created.
Generate the runtime artifacts and redefine the DEFINE method in MPC_EXT
The following code here :
METHOD define.
DATA: lo_property TYPE REF TO /iwbep/if_mgw_odata_property,
lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ.
super->define( ).
lo_entity_type = model->get_entity_type(
iv_entity_name = 'SoPrint').
IF lo_entity_type IS BOUND.
lo_property = lo_entity_type->get_property('Kunnr').
lo_property->set_as_content_type( ).
ENDIF.
ENDMETHOD.
Create a Smartform
Screenshot is given below :
Code in DPC_EXT
write code in the following method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_STREAM
METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.
DATA: ls_key_tab TYPE /iwbep/s_mgw_name_value_pair,
ls_stream TYPE ty_s_media_resource,
lv_so_id TYPE kunnr.
DATA: lv_fname TYPE rs38l_fnam,
ls_control_parameters TYPE ssfctrlop,
ls_output_options TYPE ssfcompop,
lv_device_type TYPE rspoptype,
bin_pdfx TYPE xstring,
ls_otf_data TYPE ssfcrescl.
DATA:lt_otf TYPE STANDARD TABLE OF itcoo,
lt_lines TYPE STANDARD TABLE OF tline,
t_otf_from_fm TYPE ssfcrescl.
READ TABLE it_key_tab INTO ls_key_tab WITH KEY name = 'Kunnr'.
lv_so_id = ls_key_tab-value.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZODATA'
IMPORTING
fm_name = lv_fname.
ls_output_options-tddest = 'LOCL'.
ls_output_options-xdfcmode = abap_true.
ls_output_options-xsfcmode = abap_true.
ls_output_options-tdnewid = abap_true.
ls_output_options-tdimmed = abap_true.
ls_control_parameters-no_dialog = abap_true.
ls_control_parameters-preview = space.
ls_control_parameters-getotf = abap_true.
CALL FUNCTION lv_fname
EXPORTING
control_parameters = ls_control_parameters
output_options = ls_output_options
IMPORTING
job_output_info = t_otf_from_fm
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
others= 5.
* Pass otf data to otf table
lt_otf[] = t_otf_from_fm-otfdata[].
*?Convert?OTF?to?xString
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_file = bin_pdfx
TABLES
otf = lt_otf
lines = lt_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
ls_stream-value = bin_pdfx.
ls_stream-mime_type = 'application/pdf'.
* Copy?data?to?reference
copy_data_to_ref(
EXPORTING is_data = ls_stream
CHANGING cr_data = er_stream ).
ENDMETHOD.
Finally Generate the Runtime Object.
In the end, we can show results. In a frontend fiori gateway, run /n/IWFND/GW_CLIENT.
Awesome Ratan bhai...
ReplyDelete