本文主要是介绍SAP ABAP SMARTFORMS保存为PDF到本地,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方法1.安装PFD软件,smartfomrs打印时候选择输出设备为PDF print,导出文件到本地。
方法2.代码实现。
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: gv_formname TYPE tdsfname VALUE 'ZZDEMO',
gv_fm_name TYPE rs38l_fnam.
DATA: gwa_ssfcompop TYPE ssfcompop,
gwa_control TYPE ssfctrlop.
DATA: gv_devtype TYPE rspoptype.
DATA: gv_job_output TYPE ssfcrescl.
DATA: gt_lines TYPE TABLE OF tline.
DATA: gv_size TYPE i.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*Get the function module name using form name
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = gv_formname
IMPORTING
fm_name = gv_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*Suppress print dialog
gwa_control-no_dialog = 'X'.
gwa_control-getotf = 'X'.
*Trigger the smartform
CALL FUNCTION gv_fm_name
EXPORTING
control_parameters = gwa_control
output_options = gwa_ssfcompop
IMPORTING
job_output_info = gv_job_output
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*Convert OTF to PDF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = gv_size
TABLES
otf = gv_job_output-otfdata
lines = gt_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
data:
W_FILE_NAME type string ,
W_FILE_PATH type string,
W_FULL_PATH type string .
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
PROMPT_ON_OVERWRITE = 'X'
CHANGING
FILENAME = W_FILE_NAME
PATH = W_FILE_PATH
FULLPATH = W_FULL_PATH
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4 .
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Download PDF file to presentation server
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = gv_size
filename = W_FULL_PATH
filetype = 'BIN'
TABLES
data_tab = gt_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
OTHERS = 22.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
这篇关于SAP ABAP SMARTFORMS保存为PDF到本地的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!