• 动态内表值导出为TXT文件


    输入的内表动态确定,可以修改

    代码如下

    FUNCTION ZFM_TEST_FILE.
    *"----------------------------------------------------------------------
    *"*"本地接口:
    *"  TABLES
    *"      TAB
    *"----------------------------------------------------------------------
      DATA :
        CL_TAB  TYPE REF TO  CL_ABAP_STRUCTDESCR,
        LT_FILE TYPE STANDARD TABLE OF STRING,
        WA_EILE LIKE LINE OF LT_FILE.
    
      FIELD-SYMBOLS :
        <FS_TAB> TYPE STANDARD TABLE,
        <FS_WAB> TYPE ANY,
        <FS_INT> TYPE  ABAP_COMPDESCR,
        <FS_VAL>  .
      LOOP AT TAB ASSIGNING <FS_WAB>.
        CL_TAB ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <FS_WAB> ).
        LOOP AT CL_TAB->COMPONENTS  ASSIGNING <FS_INT>.
          ASSIGN COMPONENT <FS_INT>-NAME OF STRUCTURE <FS_WAB> TO <FS_VAL>.
          IF SY-SUBRC = 0.
           IF WA_EILE IS NOT INITIAL.
             CONCATENATE WA_EILE <FS_VAL> INTO WA_EILE SEPARATED BY '|'.
             ELSE.
             WA_EILE = <FS_VAL> .
           ENDIF.
    
          ELSE.
    
          ENDIF.
    
        ENDLOOP.
        APPEND WA_EILE TO LT_FILE .
        CLEAR WA_EILE .
      ENDLOOP.
        DATA PATH TYPE string VALUE 'C:UsersjaxDesktop下载的文件'.
        path = path && '.TXT' .
    
       CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
                   EXPORTING
                     FILENAME                = PATH
    *                FILETYPE                = 'PDF'
                     CODEPAGE                = '4103' " '8400'
    *                filetype                = 'BIN'
    *                 FILETYPE                = 'BIN'
                     WRITE_BOM               = 'X'
    *                 WRITE_LF                = 'X'
                   CHANGING
                     DATA_TAB                = LT_FILE
                   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
                     NOT_SUPPORTED_BY_GUI    = 22
                     ERROR_NO_GUI            = 23
                     OTHERS                  = 24.
    
    ENDFUNCTION. 

     

    效果如图

  • 相关阅读:
    HTML5移动开发修改APP名称
    JS保留字
    基于MVC的JagaScript Web 富应用开发
    继承的另一种写法
    设置MIME使虚拟空间可以下载APK文件
    HTML5移动开发修改APP图标
    Acer Travelmate T3290笔记本拆机指南
    SQL语法用like %或in时Parameters要怎么用才能避免SQL Injection的问题
    DirectShow编译过程(转载+修改)
    webclient很好很强大
  • 原文地址:https://www.cnblogs.com/hdchen/p/7840447.html
Copyright © 2020-2023  润新知