Mobile: 135 8576 5961 / WeChat: IM_WILLIAM_C / Mail: william.chen.cn@outlook.com /
分类: 其他平台
2015-04-19 21:38:56
*& Report ZJOI_TEST01(回忆当初刚学ABAP时的练习)
*&---------------------------------------------------------------------*
*& 1.打开Windows路径窗口,获取本地文件(仅限.txt和.csv格式)路径
*& 2.读取txt文件或CSV文件(文件的Encoding格式必须是UTF-8才能读入中、日文无乱码)
*&---------------------------------------------------------------------*
REPORT ZJOI_TEST01.
PARAMETERS:
P_LCFILE TYPE IBIPPARMS-PATH. "本地文件路径
DATA:
IT_DATAFILE TYPE TABLE OF STRING, "存放Upload进来的文件内表
wa_datafile type string.
DATA L_PATH TYPE STRING.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_LCFILE.
* 获取本地文件路径
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = P_LCFILE
.
START-OF-SELECTION.
L_PATH = P_LCFILE.
* 从本地读入文件到内表中
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_PATH
FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = ' '
* 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 = IT_DATAFILE
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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* ENDIF.
IF SY-SUBRC = 0.
* 将读入的文件输出显示
LOOP AT IT_DATAFILE into wa_datafile.
write / wa_datafile.
ENDLOOP.
ENDIF.
* 用 F4_FILENAME 获取的路径和 GUI_UPLOAD 需要的路径参数类型不一样,需要中间变量转换一下哦。