下面介绍将smartforms转换成PDF文档,然后下载的实例以及相关的代码。
1, 创建smartform
Tcode:smartforms创建一个简单的smartform
添加一个文本节点,
2, 创建程序
创建程序生成smartform,然后通过CONVERT_OTF()函数将smartform转换成PDF,最后GUI_DOWNLOAD()下载到本地。
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
REPORT ztest_smartform_pdf. DATA: g_fm_name TYPE rs38l_fnam. DATA: gwa_result TYPE ssfcrescl, gwa_output TYPE ssfcompop, g_filename TYPE string, g_bin_filesize TYPE i, git_lines TYPE STANDARD TABLE OF tline, gwa_control TYPE ssfctrlop. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = 'ZTEST_PDF' * VARIANT = ' ' * DIRECT_CALL = ' ' IMPORTING fm_name = g_fm_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. gwa_control-getotf = abap_true. "取得OTF数据 gwa_control-no_dialog = abap_true. "不显示对话框 gwa_output-tddest = '024J'. "指定打印机 CALL FUNCTION g_fm_name EXPORTING control_parameters = gwa_control output_options = gwa_output IMPORTING job_output_info = gwa_result EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. * Convert content to PDF CALL FUNCTION 'CONVERT_OTF' EXPORTING format = 'PDF' IMPORTING bin_filesize = g_bin_filesize TABLES otf = gwa_result-otfdata[] lines = git_lines EXCEPTIONS err_max_linewidth = 1 err_format = 2 err_conv_not_possible = 3 OTHERS = 4. "generate file path and name CONCATENATE 'C:\temp\OC\' sy-datum sy-uzeit '.PDF' INTO g_filename. * download pdf CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING bin_filesize = g_bin_filesize filename = g_filename filetype = 'BIN' TABLES data_tab = git_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. |
运行后:
以上。
发表评论