二维码

[Smart] SMART FORMS转换生成PDF文件

Twilight发表于 2015-02-03 17:20zhongguomao 最后回复于 2017-08-09 11:44 [复制链接] 3882 1

1、SMARTForms绘制一个smart form
这里我们以Smart Forms循环中控制control-break状态为例

2、se38新建程序
  1. * Variable declarations
  2. DATA:
  3.   w_form_name    TYPE tdsfname VALUE 'YLEON_007',"smartforms 新建的smartform名称
  4.   w_fmodule      TYPE rs38l_fnam,
  5.   w_cparam       TYPE ssfctrlop,
  6.   w_outoptions   TYPE ssfcompop,
  7.   w_bin_filesize TYPE i, " Binary File Size
  8.   w_file_name    TYPE string,
  9.   w_file_path    TYPE string,
  10.   w_full_path    TYPE string.

  11. * Internal tables declaration

  12. * Internal table to hold the OTF data
  13. DATA:
  14.   t_otf         TYPE itcoo OCCURS 0 WITH HEADER LINE,

  15. * Internal table to hold OTF data recd from the SMARTFORM
  16.   t_otf_from_fm TYPE ssfcrescl,

  17. * Internal table to hold the data from the FM CONVERT_OTF
  18.   t_pdf_tab     LIKE tline OCCURS 0 WITH HEADER LINE.


  19. * This function module call is used to retrieve the name of the Function
  20. * module generated when the SMARTFORM is activated

  21. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
  22.   EXPORTING
  23.     formname           = w_form_name
  24. *   VARIANT            = ' '
  25. *   DIRECT_CALL        = ' '
  26.   IMPORTING
  27.     fm_name            = w_fmodule
  28.   EXCEPTIONS
  29.     no_form            = 1
  30.     no_function_module = 2
  31.     OTHERS             = 3.
  32. IF sy-subrc <> 0.
  33.   MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  34.   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  35. ENDIF.

  36. * Calling the SMARTFORM using the function module retrieved above
  37. * GET_OTF parameter in the CONTROL_PARAMETERS is set to get the OTF
  38. * format of the output


  39. w_cparam-no_Dialog = 'X'.
  40. w_cparam-preview = space. " Suppressing the dialog box
  41. " for print preview
  42. w_cparam-getotf = 'X'.

  43. * Printer name to be used is provided in the export parameter
  44. * OUTPUT_OPTIONS
  45. w_outoptions-tddest = 'LP01'.

  46. CALL FUNCTION w_fmodule
  47.   EXPORTING
  48. *   archive_index      =
  49. *   archive_index_tab  =
  50. *   archive_parameters =
  51.     control_parameters = w_cparam
  52. *   mail_appl_obj      =
  53. *   mail_recipient     =
  54. *   mail_sender        =
  55.     output_options     = w_outoptions
  56. *   user_settings      = 'X'
  57.   IMPORTING
  58. *   document_output_info =
  59.     job_output_info    = t_otf_from_fm
  60. *   job_output_options =
  61.   EXCEPTIONS
  62.     formatting_error   = 1
  63.     internal_error     = 2
  64.     send_error         = 3
  65.     user_canceled      = 4
  66.     OTHERS             = 5.
  67. IF sy-subrc <> 0.
  68.   MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  69.   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  70. ENDIF.

  71. t_otf[] = t_otf_from_fm-otfdata[].

  72. * Function Module CONVERT_OTF is used to convert the OTF format to PDF

  73. CALL FUNCTION 'CONVERT_OTF'
  74.   EXPORTING
  75.     format                = 'PDF'
  76.     max_linewidth         = 132
  77. *   ARCHIVE_INDEX         = ' '
  78. *   COPYNUMBER            = 0
  79. *   ASCII_BIDI_VIS2LOG    = ' '
  80. *   PDF_DELETE_OTFTAB     = ' '
  81.   IMPORTING
  82.     bin_filesize          = w_bin_filesize
  83. *   BIN_FILE              =
  84.   TABLES
  85.     otf                   = t_otf
  86.     lines                 = t_pdf_tab
  87.   EXCEPTIONS
  88.     err_max_linewidth     = 1
  89.     err_format            = 2
  90.     err_conv_not_possible = 3
  91.     err_bad_otf           = 4
  92.     OTHERS                = 5.
  93. IF sy-subrc <> 0.
  94.   MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  95.   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  96. ENDIF.

  97. * To display File SAVE dialog window
  98. CALL METHOD cl_gui_frontend_services=>file_save_dialog
  99. * EXPORTING
  100. * WINDOW_TITLE =
  101. * DEFAULT_EXTENSION =
  102. * DEFAULT_FILE_NAME =
  103. * FILE_FILTER =
  104. * INITIAL_DIRECTORY =
  105. * WITH_ENCODING =
  106. * PROMPT_ON_OVERWRITE = 'X'
  107.   CHANGING
  108.     filename             = w_file_name
  109.     path                 = w_file_path
  110.     fullpath             = w_full_path
  111. *   USER_ACTION          =
  112. *   FILE_ENCODING        =
  113.   EXCEPTIONS
  114.     cntl_error           = 1
  115.     error_no_gui         = 2
  116.     not_supported_by_gui = 3
  117.     OTHERS               = 4.
  118. IF sy-subrc <> 0.
  119.   MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  120.   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  121. ENDIF.


  122. * Use the FM GUI_DOWNLOAD to download the generated PDF file onto the
  123. * presentation server

  124. CALL FUNCTION 'GUI_DOWNLOAD'
  125.   EXPORTING
  126.     bin_filesize = w_bin_filesize
  127.     filename     = w_full_path
  128.     filetype     = 'BIN'
  129. *   APPEND       = ' '
  130. *   WRITE_FIELD_SEPARATOR = ' '
  131. *   HEADER       = '00'
  132. *   TRUNC_TRAILING_BLANKS = ' '
  133. *   WRITE_LF     = 'X'
  134. *   COL_SELECT   = ' '
  135. *   COL_SELECT_MASK = ' '
  136. *   DAT_MODE     = ' '
  137. *   CONFIRM_OVERWRITE = ' '
  138. *   NO_AUTH_CHECK = ' '
  139. *   CODEPAGE     = ' '
  140. *   IGNORE_CERR  = ABAP_TRUE
  141. *   REPLACEMENT  = '#'
  142. *   WRITE_BOM    = ' '
  143. *   TRUNC_TRAILING_BLANKS_EOL = 'X'
  144. *   WK1_N_FORMAT = ' '
  145. *   WK1_N_SIZE   = ' '
  146. *   WK1_T_FORMAT = ' '
  147. *   WK1_T_SIZE   = ' '
  148. * IMPORTING
  149. *   FILELENGTH   =
  150.   TABLES
  151.     data_tab     = t_pdf_tab
  152. *   FIELDNAMES   =
  153. * EXCEPTIONS
  154. *   FILE_WRITE_ERROR = 1
  155. *   NO_BATCH     = 2
  156. *   GUI_REFUSE_FILETRANSFER = 3
  157. *   INVALID_TYPE = 4
  158. *   NO_AUTHORITY = 5
  159. *   UNKNOWN_ERROR = 6
  160. *   HEADER_NOT_ALLOWED = 7
  161. *   SEPARATOR_NOT_ALLOWED = 8
  162. *   FILESIZE_NOT_ALLOWED = 9
  163. *   HEADER_TOO_LONG = 10
  164. *   DP_ERROR_CREATE = 11
  165. *   DP_ERROR_SEND = 12
  166. *   DP_ERROR_WRITE = 13
  167. *   UNKNOWN_DP_ERROR = 14
  168. *   ACCESS_DENIED = 15
  169. *   DP_OUT_OF_MEMORY = 16
  170. *   DISK_FULL    = 17
  171. *   DP_TIMEOUT   = 18
  172. *   FILE_NOT_FOUND = 19
  173. *   DATAPROVIDER_EXCEPTION = 20
  174. *   CONTROL_FLUSH_ERROR = 21
  175. *   OTHERS       = 22
  176.   .
  177. IF sy-subrc <> 0.
  178. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  179. * with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  180. ENDIF.
复制代码


3、程序执行效果
smartform_pdf 1.jpg
注意输出名称是需要填写扩展名.PDF
smartform_pdf 2.jpg
回复

使用道具 举报

zhongguomao
学习函数CONVERT_OTF。
回复 支持 反对

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表