A simple Smartform to PDF as a file - example. For demonstration purpose, a simple Smartform call is done which is processed via OTF info a PDF and stored on the presentation server.
DATA: it_docs TYPE STANDARD TABLE OF docs, it_lines TYPE STANDARD TABLE OF tline, st_job_output_info TYPE ssfcrescl, st_document_output_info TYPE ssfcrespd, st_job_output_options TYPE ssfcresop, st_output_options TYPE ssfcompop, st_control_parameters TYPE ssfctrlop, v_language TYPE sflangu VALUE 'E', v_e_devtype TYPE rspoptype, v_bin_filesize TYPE i, v_name TYPE string, v_path TYPE string, v_fullpath TYPE string, v_filter TYPE string, v_uact TYPE i, v_guiobj TYPE REF TO cl_gui_frontend_services, v_filename TYPE string, v_fm_name TYPE rs38l_fnam. CALL FUNCTION 'SSF_GET_DEVICE_TYPE' EXPORTING i_language = v_language i_application = 'SAPDEFAULT' IMPORTING e_devtype = v_e_devtype. st_output_options-tdprinter = v_e_devtype. st_control_parameters-no_dialog = 'X'. st_control_parameters-getotf = 'X'. "<= Important ! CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = 'ZWIMTEST' "<= Name your form IMPORTING fm_name = v_fm_name EXCEPTIONS OTHERS = 4. CHECK sy-subrc = 0. *=== Call the Smartform controller module, with the instruction * to produce OTF output CALL FUNCTION v_fm_name EXPORTING control_parameters = st_control_parameters output_options = st_output_options IMPORTING document_output_info = st_document_output_info job_output_info = st_job_output_info job_output_options = st_job_output_options EXCEPTIONS OTHERS = 4. CHECK sy-subrc = 0. *=== Concert OTF output to PDF CALL FUNCTION 'CONVERT_OTF_2_PDF' IMPORTING bin_filesize = v_bin_filesize TABLES otf = st_job_output_info-otfdata doctab_archive = it_docs lines = it_lines EXCEPTIONS OTHERS = 4. CHECK sy-subrc = 0. *=== Ask user to chose file (on presentation server) CONCATENATE 'smrt' '.pdf' INTO v_name. CREATE OBJECT v_guiobj. CALL METHOD v_guiobj->file_save_dialog EXPORTING default_extension = 'pdf' default_file_name = v_name file_filter = v_filter CHANGING filename = v_name path = v_path fullpath = v_fullpath user_action = v_uact. IF v_uact = v_guiobj->action_cancel. EXIT. ENDIF. *=== Download as a file MOVE v_fullpath TO v_filename. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING bin_filesize = v_bin_filesize filename = v_filename filetype = 'BIN' TABLES data_tab = it_lines EXCEPTIONS OTHERS = 22.