ABAP - FUNCTION - GUI_DOWNLOAD

 About File Type

'ASC' :

ASCII format. The table is transferred as text. Conversion exits are performed. The output format additionally depends on the parameters CODEPAGE, TRUNC_TRAILING_BLANKS, and TRUNC_TRAILING_BLANKS_EOL.

'IBM' :

ASCII format with IBM codepage conversion (DOS). This format corresponds to the 'ASC' format when using target codepage 1103. This codepage is frequently used for data exchange via floppy disk.

'DAT' :

Column-by-column transfer. With this format, the data is transferred as text as with ASC. However, no conversion exits are performed and the columns are separated by tab characters. This format generates files than can be uploaded again using gui_upload or ws_upload.

'DBF' :

Data is downloaded in dBase format. Since in this format the data types of the individual columns are stored as well, you can often avoid import problems, for example, into Microsoft Excel, especially when interpreting numeric values.

'WK1' :

Data is downloaded in Lotus 1-2-3 format.

'BIN' :

Binary format. Data is transferred binarily. There is no formatting and no codepage conversion. The data is interpreted row by row; it is not formatted by columns. Specify the data length in parameter BIN_FILESIZE. The table should consist of a column of type X, because especially in Unicode systems, the conversion of structured into binary data causes errors.

 

EG.Download as excel

    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
*           BIN_FILESIZE                    =
        filename                        = l_file
        filetype                        = 'ASC'
*           APPEND                          = ' '
        write_field_separator           = 'X'
*           HEADER                          = '00'
*           TRUNC_TRAILING_BLANKS           = ' '
*           WRITE_LF                        = 'X'
*           COL_SELECT                      = ' '
*           COL_SELECT_MASK                 = ' '
*           DAT_MODE                        = ' '
*           CONFIRM_OVERWRITE               = ' '
*           NO_AUTH_CHECK                   = ' '
        codepage                        = '8400'
*           IGNORE_CERR                     = ABAP_TRUE
*           REPLACEMENT                     = '#'
*           WRITE_BOM                       = ' '
*           TRUNC_TRAILING_BLANKS_EOL       = 'X'
*           WK1_N_FORMAT                    = ' '
*           WK1_N_SIZE                      = ' '
*           WK1_T_FORMAT                    = ' '
*           WK1_T_SIZE                      = ' '
*           WRITE_EOL                       = ABAP_TRUE
*         IMPORTING
*           FILELENGTH                      =
      TABLES
        data_tab                        = lt_main[]
        fieldnames                      = tab_title
*         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
              .

 

  • adhibition

    *&---------------------------------------------------------------------*
    *& Report  ZPDFDOWNLAOD
    *&---------------------------------------------------------------------*
    *&smartforms to PDF fields
    *&
    *&---------------------------------------------------------------------*

    REPORT  ZPDFDOWNLAOD.


    DATA: l_formname TYPE tdsfname.
    DATA: l_name TYPE rs38l_fnam.
    DATA: ws_composer_param       TYPE ssfcompop.
    DATA: job_output TYPE ssfcrescl.
    DATA:f_filename TYPE string,
         f_path TYPE string,
         f_fullpath TYPE string.
    DATA: i_otf LIKE itcoo OCCURS 100 WITH HEADER LINE,
          i_pdf LIKE tline OCCURS 100 WITH HEADER LINE.

    PARAMETERS:p_001 TYPE c RADIOBUTTON GROUP grp ,
               p_002 TYPE c RADIOBUTTON GROUP grp.


    START-OF-SELECTION.
      IF p_001 = 'X'.
        l_formname = 'ZWENDY_001'.
      ELSE.
        l_formname = 'ZWENDY_002'.
      ENDIF.

      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          formname                 =  l_formname
    *     VARIANT                  = ' '
    *     DIRECT_CALL              = ' '
        IMPORTING
          fm_name                  = l_name
       EXCEPTIONS
         no_form                  = 1
         no_function_module       = 2
         OTHERS                   = 3.
      IF sy-subrc <> 0.
        MESSAGE e398(00WITH '没有获取打印的form表单'.
      ENDIF.

    ***进行打印预览,获得输出otf数据
      ws_composer_param-tdimmed = 'X'.
      ws_composer_param-tddelete = 'X'.
      ws_composer_param-tddest  = 'LOCL'.
      DATA: ls_control_param LIKE ssfctrlop OCCURS 0  WITH HEADER LINE.
      ls_control_param-device    = 'PRINTER'.
      ls_control_param-no_dialog = 'X'.
      ls_control_param-preview   = 'X'.
      ls_control_param-langu     = 'E'.
      ls_control_param-getotf = 'X' .  "打印预览后生成otf数据
      APPEND ls_control_param.
      CALL FUNCTION l_name
        EXPORTING
          control_parameters = ls_control_param
          output_options     = ws_composer_param
          user_settings      = ''
        IMPORTING
          job_output_info    = job_output.  "包含otf输出数据
      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数据转换为PDF数据
      DATA:wa_toa_dara TYPE toa_dara.
      DATA:f_filesize TYPE string.
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = 'PDF'
          max_linewidth         = 132
          archive_index         = wa_toa_dara
          copynumber            = 0
    *    ascii_bidi_vis2log    = ' '
    *    pdf_delete_otftab     = ' '
        IMPORTING
          bin_filesize    = f_filesize  "一定要加,否则会数据溢出
        TABLES
          otf                   = job_output-otfdata
          lines                 = i_pdf
        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.


    ***获取文件保存路径
      CLEAR:f_filename,f_path,f_fullpath..
      CALL METHOD cl_gui_frontend_services=>file_save_dialog
        EXPORTING
          default_file_name    = '工厂外销报关文件'
          default_extension    = 'PDF'
          file_filter          = '*.PDF'
          prompt_on_overwrite  = 'X'
        CHANGING
          filename             = f_filename
          path                 = f_path
          fullpath             = f_fullpath
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.


    ***下载PDF文件
      IF f_fullpath IS NOT INITIAL.
        CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
            filename = f_fullpath
            filetype = 'BIN'
          TABLES
            data_tab = i_pdf.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ELSE.
          WRITE:/  '1、文件生成路径(双击可打开):'30 f_path.
          SKIP 1.
          WRITE:/  '2、文件名(双击可打开):',30 f_filename.
        ENDIF.
      ELSE.
        WRITE:/ '文件输出取消'.
      ENDIF.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值