SAP ABAP TXT文件上传下载

文件上传函数 : 

CALL FUNCTION 'GUI_UPLOAD'

CALL FUNCTION 'UPLOAD'

CALL FUNCTION 'WS_UPLOAD'

直接COPY代码即可,要测哪个DEMO,哪个DEMO取消注释。

案例:

TYPES : BEGIN OF ty_alv ,
          ebeln TYPE char20,
          ebelp TYPE char20,
        END OF ty_alv .

DATA : gt_alv TYPE TABLE OF ty_alv,
       gs_alv TYPE ty_alv.

*DEMO1
*  CALL FUNCTION 'GUI_UPLOAD'
*    EXPORTING
*      codepage            = '4110' "8400任然会乱码
*      filename            = 'C:\Users\25073\Desktop\2022.07.25.txt'
*      filetype            = 'ASC'  "ASC为文本格式,BIN会乱码
*      has_field_separator = 'X'    "用tab键分隔
*      read_by_line        = 'X'    "读取文件放置内表
*    TABLES
*      data_tab            = gt_alv.


*DEMO2.
* CALL FUNCTION 'UPLOAD'
*   EXPORTING
*     codepage            = '4110'
*     filename            = 'C:\Users\25073\Desktop\2022.07.25.txt'
*     filetype            = 'DAT'
*     item                = '上传文件TEXT'
*   TABLES
*     data_tab            = gt_alv
*   EXCEPTIONS
*     conversion_error    = 1
*     invalid_table_width = 2
*     invalid_type        = 3.


*DEMO3.
* CALL FUNCTION 'WS_UPLOAD'
*   EXPORTING
*     codepage = '4110'
*     filename = ''
*     filetype = 'DAT'
*   TABLES
*     data_tab = gt_alv.

LOOP AT gt_alv INTO gs_alv .
  WRITE : / gs_alv-ebeln , gs_alv-ebelp .
ENDLOOP .

推荐使用GUI_UPLOAD,WS_UPLOAD是一个要被GUI_UPLOAD替代的funtion,所以以后写程序就都用GUI_UPLOAD就好了

文件下载函数:

CALL FUNCTION 'DOWNLOAD'

CALL FUNCTION 'WS_DOWNLOAD'

CALL FUNCTION 'GUI_DOWNLOAD'

案例

TYPES : BEGIN OF ty_alv ,
          col01 TYPE char10,
          col02 TYPE char10,
        END OF ty_alv .

DATA : gt_alv TYPE TABLE OF ty_alv,
       gs_alv TYPE ty_alv.

DATA: fname(128), ftype(3), fsize TYPE i.

DO 10 TIMES .
  gs_alv-col01 = gs_alv-col01 + 2 .
  gs_alv-col02 = gs_alv-col02 + 4 .
  APPEND gs_alv TO gt_alv .
ENDDO.

*DEMO1
*CALL FUNCTION 'DOWNLOAD'
*  EXPORTING
*    codepage            = 'IBM'
*    filename            = ''                     "默认文件地址
*    filetype            = 'DAT'                  "文件类型
*    item                = 'TXT文件下载'          "选择文件的表头
*    mode                = ''
*  IMPORTING
*    act_filename        = fname
*    act_filetype        = ftype
*    filesize            = fsize
*  TABLES
*    data_tab            = gt_alv
*  EXCEPTIONS
*    invalid_filesize    = 1
*    invalid_table_width = 2
*    invalid_type        = 3.

*DEMO2
*CALL FUNCTION 'WS_DOWNLOAD'
*  EXPORTING
*    filename                = 'C:\Users\25073\Desktop\108.txt'
*    filetype                = 'DAT'
*    MODE                    = 'A'
*  TABLES
*    data_tab                = gt_alv
*  EXCEPTIONS
*    file_open_error         = 1
*    file_write_error        = 2
*    invalid_filesize        = 3
*    invalid_type            = 4
*    no_batch                = 5
*    unknown_error           = 6
*    invalid_table_width     = 7
*    gui_refuse_filetransfer = 8
*    customer_error          = 9
*    OTHERS                  = 10.

*DEMO3
*CALL FUNCTION 'GUI_DOWNLOAD'
*  EXPORTING
**   BIN_FILESIZE                    =
*    filename = 'C:\Users\25073\Desktop\1008.txt '
*    filetype = 'DAT'
*    APPEND   = 'A'
*  TABLES
*    data_tab = gt_alv.

IF sy-subrc = 0 .
  WRITE : '下载成功' .
ELSE .
  WRITE : '下载失败' .
ENDIF.

你可能感兴趣的:(运维,服务器)