文件的上传

  前提条件:

PARAMETERS P_files TYPE RLGRAP-FILENAME.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_files.

一。文件的上传

函数: WS_FILENAME_GET 获取文件名

” MASK 函数 第一个逗号是标识逗号,后面每两个逗号为一组 前面为名字后面为格式(后缀名),结束加句号
” 第一个逗号是显示什么,后面指扩展名是什么

CALL FUNCTION ‘WS_FILENAME_GET’ ” 函数已过时  但还可以继续使用
EXPORTING
* DEF_FILENAME = ‘ ‘ ” 默认文件名称
* DEF_PATH = ‘ ‘ ” 默认文件路径
MASK = ‘,Excel(*.xls),*.XLS,text.txt,*.txt.’ ” 用于本地的文件的获取
MODE = ‘O’ ” S 保存 O 打开
TITLE = ‘打开文件’ ” 窗口的显示名称
IMPORTING
FILENAME = P_FILES.
* RC =
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

DATA LV_FILES TYPE STRING.
LV_FILES = P_FILES. ” 将文件名转换成string类型的变量
* 文件的上传 TXT文件的上传

CALL FUNCTION ‘GUI_UPLOAD’ ” 获取文件内容到内表中
EXPORTING
filename = LV_FILES ” string类型 要将文件转换为string类型
* FILETYPE = ‘ASC’
HAS_FIELD_SEPARATOR = ‘X’
* HEADER_LENGTH = 0
* READ_BY_LINE = ‘X’
* DAT_MODE = ‘ ‘
* CODEPAGE = ‘ ‘
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = ‘#’
* CHECK_BOM = ‘ ‘
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ‘ ‘
* IMPORTING
* FILELENGTH =
* HEADER =
tables
data_tab = GT_MATNRIAL    ” 定义的接受内表,里面的变量与上传的文件的变量一致
* CHANGING
* ISSCANPERFORMED = ‘ ‘
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
OTHERS = 17
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.   

版权声明:本文为abapweb原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/abapweb/p/13846295.html