How to Convert Smartform Output into PDF Format ?
- Nowadays PDF are most widely accepted format.
- So, Customers always wants smartforms output into PDF format.
- So, to convert our smartform output into PDF format, we will follow the below steps.
Steps to Convert smartform into PDF :-
- Step 1 :- We will call the function module of smartform in our program.
- Step 2 :- We will get the OTF ( Output text format ) for our SMARTFORM.
- Step 3 :- We will use function module CONVERT_OTF_2_PDF, OR CONVERT_OTF to convert the OTF data into the PDF.
- Step 4 :- Fourth step is to choose the location of file where you want to store the PDF.
-
For this purpose, either we can copy the location of file and paste it.
OR
-
We can use F4_FILENAME function module OR FILE_OPEN_DIALOG method of CL_GUI_FRONTEND_SERVICES class to select the file location.
-
- Step 5 :- We need to download the pdf file.
- For this purpose, we also have two options, either we can use GUI_DOWNLOAD function module OR
- we can use GUI_DOWNLOAD method of CL_GUI_FRONTEND_SERVICES class to download the file.
- Step 6 :- Now we need to open / execute the downloaded file, for the same purpose, we have EXECUTE method in CL_GUI_FRONTEND_SERVICES class to execute the file.
Solution :-
-
Step 1 :- Call the function module of our smartform in the ABAP Editor.
-
Step 2 :- Pass GET_OTF = ‘X’ in control parameters.
-
Step 3 :- we will get the OTF data via the JOB_OUTPUT_INFO parameter in Importing tab.
-
Step 4 :- Now we can use CONVERT_OTF_2_PDF function module to convert OTF into PDF format.
-
Step 5 :- We, have the PDF data so we will use, FILE_OPEN_DIALOG method of CL_GUI_FRONTED_SERVICES class to select the file of our local system.
-
Step 6 :- Now we can use GUI_DOWNLOAD method of CL_GUI_FRONTEND_SERVICES to download the pdf.
-
Step 7 :- Now, we have file downloaded into our local system, so we can open it. we have default method in SAP EXECUTE of CL_GUI_FRONTEND_SERVICES class which can open any file of our local system.
Code :-
*&---------------------------------------------------------------------*
*& Report ZAR_PDF
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZAR_PDF.
PARAMETERS : p_emp_id type ZAR_EMPLOYEE_ID.
DATA : lv_formname type TDSFNAME.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZAR_SMARTFORM_IMAGE'
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
FM_NAME = lv_formname
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3
.
DATA : ls_control type SSFCTRLOP.
DATA : ls_output type SSFCRESCL.
ls_control-getotf = 'X'.
CALL FUNCTION lv_formname
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
CONTROL_PARAMETERS = ls_control
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
* OUTPUT_OPTIONS =
* USER_SETTINGS = 'X'
p_emp_id = p_emp_id
IMPORTING
* DOCUMENT_OUTPUT_INFO =
JOB_OUTPUT_INFO = ls_output
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
.
DATA : lt_docs type table of DOCS.
DATA : lt_lines type table of TLINE.
CALL FUNCTION 'CONVERT_OTF_2_PDF'
* EXPORTING
* USE_OTF_MC_CMD = 'X'
* ARCHIVE_INDEX =
* IMPORTING
* BIN_FILESIZE =
TABLES
otf = ls_output-otfdata
doctab_archive = lt_docs
LINES = lt_lines
EXCEPTIONS
ERR_CONV_NOT_POSSIBLE = 1
ERR_OTF_MC_NOENDMARKER = 2
OTHERS = 3
.
DATA : lt_file type table of FILE_TABLE.
DATA : lo_rc type i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
* EXPORTING
* window_title =
* default_extension =
* default_filename =
* file_filter =
* with_encoding =
* initial_directory =
* multiselection =
CHANGING
file_table = lt_file
rc = lo_rc
* user_action =
* file_encoding =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
others = 5
.
DATA : lo_file type string.
READ TABLE lt_file into data(ls_file) index 1.
if sy-subrc eq 0.
lo_file = ls_file-filename.
endif.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = lo_file
filetype = 'BIN'
changing
data_tab = lt_lines
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
others = 24
.
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
document = lo_file
* application =
* parameter =
* default_directory =
* maximized =
* minimized =
* synchronous =
operation = 'OPEN'
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
synchronous_failed = 8
not_supported_by_gui = 9
others = 10
.
Execute :-
- Select the file, press allow → press allow
Comments
Post a Comment