主要的幾個功能
開始對指定的目錄進行讀取
CALL 'C_DIR_READ_START'
依序捉取目前指定路徑的 Folder
CALL 'C_DIR_READ_NEXT'
結束前面 C_DIR_READ_START 功能,通常在程式一開始會先呼叫一次,避勉其他程式漏了呼叫 C_DIR_READ_FINISH 造成異常
CALL 'C_DIR_READ_FINISH'
SAMPLE CODE:
REPORT Z_EX_GET_APSVR_FILE.
"Reference EPS_GET_DIRECTORY_LISTING
DATA: L_PATH(500).
DATA: BEGIN OF GS_FILE,
DIRECTORY(75) TYPE C, " name of directory. (possibly truncated.)
NAME(500) TYPE C, " name of entry. (possibly truncated.)
TYPE(10) TYPE C, " type of entry: directory, file
LEN(8) TYPE P, " length in bytes
OWNER(8) TYPE C, " owner of the entry
MTIME(6) TYPE P, " last modification date, seconds since 1970
MODE(9) TYPE C, " like "rwx-r-x--x":protection mode
ERRNO(3) TYPE C,
ERRMSG(40) TYPE C,
MOD_DATE TYPE D,
MOD_TIME(8) TYPE C, " hh:mm:ss
SUBRC LIKE SY-SUBRC,
END OF GS_FILE.
DATA: LS_FILE LIKE GS_FILE.
DATA: L_SUBRC LIKE SY-SUBRC.
DATA: L_TIME(10),
L_DATE LIKE SY-DATUM.
L_PATH = '/var/tmp'.
"確定前一次 C_DIR_READ_START 已結束
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD LS_FILE-ERRNO
ID 'ERRMSG' FIELD LS_FILE-ERRMSG.
CALL 'C_DIR_READ_START' ID 'DIR' FIELD L_PATH
ID 'FILE' FIELD '*'
ID 'ERRNO' FIELD LS_FILE-ERRNO
ID 'ERRMSG' FIELD LS_FILE-ERRMSG.
DO.
CLEAR LS_FILE.
"Get File List In Forlat
CALL 'C_DIR_READ_NEXT'
ID 'TYPE' FIELD LS_FILE-TYPE
ID 'NAME' FIELD LS_FILE-NAME
ID 'LEN' FIELD LS_FILE-LEN
ID 'OWNER' FIELD LS_FILE-OWNER
ID 'MTIME' FIELD LS_FILE-MTIME
ID 'MODE' FIELD LS_FILE-MODE
ID 'ERRNO' FIELD LS_FILE-ERRNO
ID 'ERRMSG' FIELD LS_FILE-ERRMSG.
L_SUBRC = SY-SUBRC.
IF L_SUBRC NE 0.
EXIT.
ENDIF.
"get file Modify Date Time
PERFORM p6_to_date_time_tz(rstr0400) USING LS_FILE-MTIME
L_TIME
L_DATE.
WRITE:/1(20) LS_FILE-TYPE,
21(20) LS_FILE-NAME,
42(10) LS_FILE-LEN,
63(10) L_DATE,
74(10) L_TIME.
ENDDO.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD LS_FILE-ERRNO
ID 'ERRMSG' FIELD LS_FILE-ERRMSG.
比較要注意的是捉回的 MTIME 是一串數字,需要透過 PERFORM p6_to_date_time_tz(rstr0400) 轉換成 Date & Time,此功能捉取的時間不用管 GMT
產生的結果
沒有留言:
張貼留言