Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Read dynamic file name

former_member185846
Active Participant
0 Kudos

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

3 REPLIES 3

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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