CALL FUNCTION 'GUI_UPLOAD' 与
CALL FUNCTION 'WS_UPLOAD' 函数都可以上传TXT文件到内表,但是还是存在一点点区别;注意红色部分,上传的文件先把标题行删除:
*&---------------------------------------------------------------------*
*& Report Z_DYG_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&上传文件标题先删除
*&---------------------------------------------------------------------*
REPORT Z_DYG_UPLOAD.
tables:marc,makt,mkpf,mseg .
*测试上传方式
data:begin of up_info occurs 0,
matnr like marc-matnr,
maktx like makt-maktx,
budat like mkpf-budat,
erfmg like mseg-erfmg,
end of up_info.
DATA: filename TYPE string ,
lf_rc TYPE c ,
col type i .
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-B01.
parameters:up_s as checkbox.
*Parameters : s_fname LIKE rlgrap-filename default 'C:\up_info.txt' OBLIGATORY.
parameters:F_NAME LIKE rlgrap-filename lower case .
SELECTION-SCREEN END OF BLOCK B1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR f_name .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = f_name.
AT SELECTION-SCREEN .
filename = f_name.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = filename
RECEIVING
result = lf_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF lf_rc <> 'X'.
MESSAGE e000(oo) WITH 'The file is not exits' .
ENDIF.
START-OF-SELECTION.
if up_s = 'X' .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
filetype = 'DAT'
TABLES
data_tab = up_info
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16 .
if sy-subrc <> 0 .
write: sy-subrc .
endif.
write:/ '---------------------------------上传文件数据1-------------------------------------' .
loop at up_info.
write:/ '物料号',up_info-matnr,
'描述',up_info-maktx,
'日期',up_info-budat,
'数量',up_info-erfmg .
endloop.
clear up_info[].
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = f_name
filetype = 'DAT'
TABLES
data_tab = up_info .
write:/ '---------------------------------上传文件数据2-------------------------------------' .
loop at up_info.
write:/ '物料号',up_info-matnr,
'描述',up_info-maktx,
'日期',up_info-budat,
'数量',up_info-erfmg .
endloop.
endif.
阅读(1613) | 评论(0) | 转发(0) |