打印详细讲解

DATA: lv_func_module_name   TYPE rs38l_fnam, "打印程序函数名
      lv_sformname          TYPE tdsfname, "smartforms名称
      ls_control_parameters TYPE ssfctrlop,
      ls_output             TYPE ssfcompop,
      ls_job_output_info    TYPE ssfcrescl,
      ls_ssfcrespd          TYPE ssfcrespd,
      lv_index              TYPE i.

"PDF变量
DATA:lv_file_size TYPE i, "PDF文件大小
     lv_bin_fiel  TYPE xstring, "二进制文件流
     lt_lines     TYPE STANDARD TABLE OF tline,
     lt_otfdata   TYPE tsfotf. "OTF数据

  lv_sformname = 'ZSFPP_001'.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = lv_sformname
    IMPORTING
      fm_name            = lv_func_module_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.

* 打印参数赋值
  ls_control_parameters-no_open = 'X'.
  ls_control_parameters-no_close = ''.    
  ls_control_parameters-getotf          = 'X'."返回OTF表

 LOOP AT gt_data5 ASSIGNING FIELD-SYMBOL(<fs_data5>) .

      AT END OF lgort.

        CALL FUNCTION 'SSF_OPEN'
          EXPORTING
            control_parameters = ls_control_parameters
          EXCEPTIONS
            formatting_error   = 1
            internal_error     = 2
            send_error         = 3
            user_canceled      = 4
            OTHERS             = 5.

        "调用smartforms
        CALL FUNCTION lv_func_module_name
          EXPORTING
            control_parameters = ls_control_parameters
            gs_head            = gs_data7
            gv_title           = gv_title
          IMPORTING
            job_output_info    = ls_job_output_info
          TABLES
            gt_item            = gt_data7
          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.

        "OTF数据赋值
        APPEND LINES OF ls_job_output_info-otfdata TO lt_otfdata.

      ENDAT.

    ENDLOOP.
   
    CALL FUNCTION 'SSF_CLOSE'
      EXCEPTIONS
        formatting_error = 1
        internal_error   = 2
        send_error       = 3
        OTHERS           = 4.
 
   "SMARTFORMS转PDF
    CALL FUNCTION 'CONVERT_OTF'
      EXPORTING
        format                = 'PDF'
      IMPORTING
        bin_filesize          = lv_file_size
      TABLES
        otf                   = lt_otfdata
        lines                 = lt_lines
      EXCEPTIONS
        err_max_linewidth     = 1
        err_format            = 2
        err_conv_not_possible = 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.

***BEGIN&-------------------保存PDF文件到本地----------------******************************
    DATA: lv_filename TYPE string, "保存pdf文件名
          lv_path     TYPE string,
          lv_fullpath TYPE string, "文件全路径
          lv_user_act TYPE i. "用户操作类型

    lv_filename = gv_title && '.pdf'.
    CALL METHOD cl_gui_frontend_services=>file_save_dialog "保存文件 窗口
      EXPORTING
        window_title              = '保存文件'
        default_extension         = 'PDF' "文件后缀
        default_file_name         = lv_filename "文件名
*       with_encoding             =
        file_filter               = '*.PDF'
*       initial_directory         =
        prompt_on_overwrite       = 'X'
      CHANGING
        filename                  = lv_filename
        path                      = lv_path
        fullpath                  = lv_fullpath
        user_action               = lv_user_act "用户操作类型
*       file_encoding             =
      EXCEPTIONS
        cntl_error                = 1
        error_no_gui              = 2
        not_supported_by_gui      = 3
        invalid_default_file_name = 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.
    ELSE.
      IF lv_user_act = cl_gui_frontend_services=>action_cancel.
        MESSAGE '取消存取' TYPE 'S' DISPLAY LIKE 'E'.
      ENDIF.
    ENDIF.

    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        bin_filesize            = lv_file_size
        filename                = lv_fullpath
        filetype                = 'BIN'
*       APPEND                  = ' '
*   IMPORTING
*       FILELENGTH              =
      TABLES
        data_tab                = lt_lines
*       FIELDNAMES              =
      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.

方法二:smartforms转换成PDF[CONVERT_OTF] | 摆渡SAP (baidusap.com)

Smart Form主要通过SSFCTRLOP和SSFCOMPOP两个参数来配置打印控制的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值