Using method CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE, it is possible to open a smartform PDF in a Web Dynpro ABAP application without the need for an InteractiveForm UI element.
You need to open a smartform PDF when the user clicks a custom print button on a view.
On your view, create a button UI element with onAction event, PRINT.
In the action handler method for action PRINT, write the following code.
DATA lv_smartform TYPE rs38l_fnam.
DATA ls_ssfctrlop TYPE ssfctrlop.
DATA ls_output_options TYPE ssfcompop.
DATA ls_job_output_info TYPE ssfcrescl.
DATA lt_lines TYPE STANDARD TABLE OF tline.
DATA lv_bin_filesize TYPE i.
DATA lv_pdf_xstring TYPE xstring.
* -- Get the name of the smartform function module
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZMY_SMARTFORM'
IMPORTING
fm_name = lv_smartform.
* -- Call the smartform
ls_ssfctrlop-no_dialog = abap_true.
ls_ssfctrlop-getotf = abap_true.
ls_output_options-tdprinter = 'PDF1'.
CALL FUNCTION lv_smartform
EXPORTING
control_parameters = ls_ssfctrlop
output_options = ls_output_options
custom_input = ls_your_custom_smartform_input
IMPORTING
job_output_info = ls_job_output_info
EXCEPTIONS
OTHERS = 0.
* -- Convert the OTF data to xstring
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = lv_bin_filesize
bin_file = lv_pdf_xstring
TABLES
otf = ls_job_output_info-otfdata[]
lines = lt_lines
EXCEPTIONS
OTHERS = 0.
CHECK lv_pdf_xstring IS NOT INITIAL.
* -- Open the PDF
cl_wd_runtime_services=>attach_file_to_response(
i_filename = 'mypdf.pdf'
i_content = lv_pdf_xstring
i_mime_type = 'application/pdf'
).
After saving and activating the Web Dynpro Component and running the application, clicking the new custom print button opens the smartform PDF.
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 | |
8 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 |