smartforms转换成PDF[CONVERT_OTF]详解编程语言

下面介绍将smartforms转换成PDF文档,然后下载的实例以及相关的代码。

1, 创建smartform

Tcode:smartforms创建一个简单的smartform

2017-02-23_10-48-08

添加一个文本节点,

2017-02-23_10-50-10

2, 创建程序

创建程序生成smartform,然后通过CONVERT_OTF()函数将smartform转换成PDF,最后GUI_DOWNLOAD()下载到本地。

代码如下:

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.

运行后:

2017-02-23_11-34-23

以上。

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/19215.html

(0)
上一篇 2021年7月19日 21:56
下一篇 2021年7月19日 21:56

相关推荐

发表回复

登录后才能评论