2007 Jul 16 10:05 AM
Hi,
I have several files created on my application server. I need to read the latest one which is created , is there a way to know when a particular file was created ? I do not have Date & time as part of filename.
Thanks,
2007 Jul 16 10:10 AM
Hi
try to use this code:
DATA: FILE_LIST LIKE STANDARD TABLE OF RSFILLST WITH HEADER LINE,
DIRNAME,
FILENM LIKE RSMRGSTR-NAME,
RC LIKE SY-SUBRC.
DATA: PATTERN LIKE RSMRGSTR-NAME.
DATA: SAP_YES(1) VALUE 'X',
SAP_NO(1) VALUE ' '.
DATA: NO_CS VALUE ' '.
*DATA FILE like FILE_LIST.
DATA: BEGIN OF FILE,
DIRNAME(75) TYPE C, " name of directory. (possibly truncated.)
NAME(75) TYPE C, " name of entry. (possibly truncated.)
TYPE(10) TYPE C, " type of entry.
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
FMODE(9) TYPE C, " like "rwx-r-x--x": protection mode.
USEABLE(1) TYPE C,
SUBRC(4) TYPE C,
ERRNO(3) TYPE C,
ERRMSG(40) TYPE C,
MOD_DATE TYPE D,
MOD_TIME(8) TYPE C, " hh:mm:ss
SEEN(1) TYPE C,
CHANGED(1) TYPE C,
END OF FILE.
DATA: ERRCNT(2) TYPE P VALUE 0.
CALL 'C_DIR_READ_FINISH' " just to be sure
ID 'ERRNO' FIELD FILE_LIST-ERRNO
ID 'ERRMSG' FIELD FILE_LIST-ERRMSG.
CALL 'C_DIR_READ_START' ID 'DIR' FIELD DIRNAME
ID 'FILE' FIELD FILENM
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
IF SY-SUBRC <> 0.
RC = SY-SUBRC.
EXIT.
ENDIF.
DO.
CLEAR FILE.
CALL 'C_DIR_READ_NEXT'
ID 'TYPE' FIELD FILE-TYPE
ID 'NAME' FIELD FILE-NAME
ID 'LEN' FIELD FILE-LEN
ID 'OWNER' FIELD FILE-OWNER
ID 'MTIME' FIELD FILE-MTIME
ID 'MODE' FIELD FILE-FMODE
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
FILE-DIRNAME = DIRNAME.
MOVE SY-SUBRC TO FILE-SUBRC.
CASE SY-SUBRC.
WHEN 0.
CLEAR: FILE-ERRNO, FILE-ERRMSG.
CASE FILE-TYPE(1).
WHEN 'F'. " normal file.
WHEN 'f'. " normal file.
WHEN OTHERS. " directory, device, fifo, socket,...
MOVE SAP_NO TO FILE-USEABLE.
ENDCASE.
IF FILE-LEN = 0.
MOVE SAP_NO TO FILE-USEABLE.
ENDIF.
WHEN 1.
EXIT.
WHEN OTHERS. " SY-SUBRC >= 2
ADD 1 TO ERRCNT.
IF ERRCNT > 10.
EXIT.
ENDIF.
IF SY-SUBRC = 5.
MOVE: '???' TO FILE-TYPE,
'???' TO FILE-OWNER,
'???' TO FILE-FMODE.
ELSE.
ENDIF.
MOVE SAP_NO TO FILE-USEABLE.
ENDCASE.
* Convert the date/time format
PERFORM P6_TO_DATE_TIME_TZ(RSTR0400) USING FILE-MTIME
FILE-MOD_TIME
FILE-MOD_DATE.
* * Does the filename contains the requested pattern?
* * Then store it, else forget it.
IF PATTERN = NO_CS.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ELSE.
IF FILE-NAME CP PATTERN.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ENDIF.
ENDIF.
ENDDO.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD FILE_LIST-ERRNO
ID 'ERRMSG' FIELD FILE_LIST-ERRMSG.
IF SY-SUBRC <> 0.
ENDIF.
U should read all files for a certain path and get the date wheh they was created or changed.
Max
2007 Jul 16 10:07 AM
2007 Jul 16 10:08 AM
Sorry I did not clarify enough I want to do it through a program.
2007 Jul 16 10:10 AM
Hello,
so use fm EPS_GET_DIRECTORY_LISTING
and sort corresp. table DIR_LIST
Regards,
Vasanth
2007 Jul 16 10:11 AM
2007 Jul 16 10:10 AM
Hi
try to use this code:
DATA: FILE_LIST LIKE STANDARD TABLE OF RSFILLST WITH HEADER LINE,
DIRNAME,
FILENM LIKE RSMRGSTR-NAME,
RC LIKE SY-SUBRC.
DATA: PATTERN LIKE RSMRGSTR-NAME.
DATA: SAP_YES(1) VALUE 'X',
SAP_NO(1) VALUE ' '.
DATA: NO_CS VALUE ' '.
*DATA FILE like FILE_LIST.
DATA: BEGIN OF FILE,
DIRNAME(75) TYPE C, " name of directory. (possibly truncated.)
NAME(75) TYPE C, " name of entry. (possibly truncated.)
TYPE(10) TYPE C, " type of entry.
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
FMODE(9) TYPE C, " like "rwx-r-x--x": protection mode.
USEABLE(1) TYPE C,
SUBRC(4) TYPE C,
ERRNO(3) TYPE C,
ERRMSG(40) TYPE C,
MOD_DATE TYPE D,
MOD_TIME(8) TYPE C, " hh:mm:ss
SEEN(1) TYPE C,
CHANGED(1) TYPE C,
END OF FILE.
DATA: ERRCNT(2) TYPE P VALUE 0.
CALL 'C_DIR_READ_FINISH' " just to be sure
ID 'ERRNO' FIELD FILE_LIST-ERRNO
ID 'ERRMSG' FIELD FILE_LIST-ERRMSG.
CALL 'C_DIR_READ_START' ID 'DIR' FIELD DIRNAME
ID 'FILE' FIELD FILENM
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
IF SY-SUBRC <> 0.
RC = SY-SUBRC.
EXIT.
ENDIF.
DO.
CLEAR FILE.
CALL 'C_DIR_READ_NEXT'
ID 'TYPE' FIELD FILE-TYPE
ID 'NAME' FIELD FILE-NAME
ID 'LEN' FIELD FILE-LEN
ID 'OWNER' FIELD FILE-OWNER
ID 'MTIME' FIELD FILE-MTIME
ID 'MODE' FIELD FILE-FMODE
ID 'ERRNO' FIELD FILE-ERRNO
ID 'ERRMSG' FIELD FILE-ERRMSG.
FILE-DIRNAME = DIRNAME.
MOVE SY-SUBRC TO FILE-SUBRC.
CASE SY-SUBRC.
WHEN 0.
CLEAR: FILE-ERRNO, FILE-ERRMSG.
CASE FILE-TYPE(1).
WHEN 'F'. " normal file.
WHEN 'f'. " normal file.
WHEN OTHERS. " directory, device, fifo, socket,...
MOVE SAP_NO TO FILE-USEABLE.
ENDCASE.
IF FILE-LEN = 0.
MOVE SAP_NO TO FILE-USEABLE.
ENDIF.
WHEN 1.
EXIT.
WHEN OTHERS. " SY-SUBRC >= 2
ADD 1 TO ERRCNT.
IF ERRCNT > 10.
EXIT.
ENDIF.
IF SY-SUBRC = 5.
MOVE: '???' TO FILE-TYPE,
'???' TO FILE-OWNER,
'???' TO FILE-FMODE.
ELSE.
ENDIF.
MOVE SAP_NO TO FILE-USEABLE.
ENDCASE.
* Convert the date/time format
PERFORM P6_TO_DATE_TIME_TZ(RSTR0400) USING FILE-MTIME
FILE-MOD_TIME
FILE-MOD_DATE.
* * Does the filename contains the requested pattern?
* * Then store it, else forget it.
IF PATTERN = NO_CS.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ELSE.
IF FILE-NAME CP PATTERN.
MOVE-CORRESPONDING FILE TO FILE_LIST.
APPEND FILE_LIST.
ENDIF.
ENDIF.
ENDDO.
CALL 'C_DIR_READ_FINISH'
ID 'ERRNO' FIELD FILE_LIST-ERRNO
ID 'ERRMSG' FIELD FILE_LIST-ERRMSG.
IF SY-SUBRC <> 0.
ENDIF.
U should read all files for a certain path and get the date wheh they was created or changed.
Max
2007 Jul 16 10:38 AM
If u have not defined directory path for ur file then u can check the file
in root directory <b>./</b> in AL11..
that contains ur file...
If u have specified the directory name then u can check the in specified directory..
Regards
Prax