11-27-2011 5:41 PM
Dear Experts,
I need to read a file from the application server with the file name "static""timestamp".txt, where static is the static file name and timestamp would be added at the end of the file name. Please suggest me a way to read all such files one by one.
thanks
11-27-2011 5:57 PM
Hi
You need to scan the path in order to get all files stored and then to read it;
You can use the fm EPS_GET_DIRECTORY_LISTING in order to scan the directory:
DATA: dir_name LIKE epsf-epsdirnam,
file_mask LIKE epsf-epsfilnam.
DATA: filename TYPE string.
DATA: t_dir_list TYPE STANDARD TABLE OF epsfili WITH HEADER LINE.
dir_name = '<application path name>'.
file_mask = '<static>*.*'.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
dir_name = dir_name
file_mask = file_mask
TABLES
dir_list = t_dir_list
EXCEPTIONS
invalid_eps_subdir = 1
sapgparam_failed = 2
build_directory_failed = 3
no_authorization = 4
read_directory_failed = 5
too_many_read_errors = 6
empty_directory_list = 7
OTHERS = 8.
IF sy-subrc <> 0.
ENDIF.
LOOP AT t_dir_list.
CONCATENATE dir_name '/' t_dir_list-name INTO filename.
OPEN DATASET filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.
.........
CLOSE DATASET filename.
ENDLOOP.
Max
11-27-2011 6:35 PM
Thanks for the prompt reply, Max. Is there a way to delete the file once it is processed? Because, I want to read the file and delete it from the directory.
11-27-2011 10:45 PM
Yes of course
After reading it you need to use DELETE DATASET statament to delete the file:
LOOP AT t_dir_list.
CONCATENATE dir_name '/' t_dir_list-name INTO filename.
OPEN DATASET filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.
.........
CLOSE DATASET filename.
DELETE DATASET filename.
ENDLOOP.
Max