ABAP:Smartform生成PDF
注意:生成PDF时,Smartform中的参数 control_parameters-getotf = 'X'. 必须
*&---------------------------------------------------------------------*
*& REPORT ZHARPO_010
*&
*&---------------------------------------------------------------------*
*&
*& Smartform生成PDF,可设置不显示Smartform打印窗口
*&---------------------------------------------------------------------*
REPORT zharpo_010 NO STANDARD PAGE HEADING.
TABLES rlgrap.
DATA fm_name TYPE rs38l_fnam.
DATA control_parameters TYPE ssfctrlop.
DATA job_output_info TYPE ssfcrescl.
DATA job_output_options TYPE ssfcresop.
DATA itab TYPE TABLE OF bkpf.
DATA BEGIN OF pdf OCCURS 10.
INCLUDE STRUCTURE tline.
DATA END OF pdf.
DATA len TYPE i. "PDF文件大小
PARAMETERS filename TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
PERFORM f4_file_save CHANGING filename.
START-OF-SELECTION.
SELECT bukrs belnr bldat
UP TO 300 ROWS
INTO CORRESPONDING FIELDS OF TABLE itab
FROM bkpf.
control_parameters-getotf = 'X'. "此参数必须,否则不会导出PDF而直接显示smartform
control_parameters-no_close = ' '.
control_parameters-no_dialog = 'X'. "不显示打印对话框
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZHARPO_001'
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
CHECK: sy-subrc = 0.
CALL FUNCTION fm_name
EXPORTING
control_parameters = control_parameters
IMPORTING
job_output_info = job_output_info
job_output_options = job_output_options
TABLES
itab2 = itab
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
CHECK: sy-subrc = 0.
* convert smartforms to PDF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = len
TABLES
otf = job_output_info-otfdata
lines = pdf
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
CHECK: sy-subrc = 0.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = filename
filetype = 'BIN'
bin_filesize = len
TABLES
data_tab = pdf
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE 'ERROR!' TYPE 'E'.
ENDIF.
*&---------------------------------------------------------------------*
*& Form F4_FILE_SAVE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_FILENAME text
*----------------------------------------------------------------------*
FORM f4_file_save CHANGING p_file.
DATA: l_file TYPE string.
DATA: l_path TYPE string.
DATA: l_fullpath TYPE string.
l_file = p_file.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_file_name = l_file
initial_directory = l_path
CHANGING
filename = l_file
path = l_path
fullpath = l_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc = 0.
p_file = l_fullpath.
ELSE.
ENDIF.
ENDFORM. " F4_FILE_OPEN