cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read a directory and then use each file name in an InfoPackage?

0 Kudos

I have a strange project and need expert help. I am sure I am not the first one to try this.

1) 100+ Users each drop a file into a common directory with the name 'File####.xlsx' where '####' is the user's area

2) In a Process Chain, I need to get a listing of the directory filenames with Abap (I assume)

3) Then I need to loop through the list of file names and use each file name in an InfoPackage or DTP to load the contents of the file.

Accepted Solutions (0)

Answers (1)

Answers (1)

Kurt,

Not such an unusual requirement. And it's more straightforward with infopackages than with DTPs.

Many ways to do it - but here's one way:

A process chain can call a program that does the following:

1) reads the specified directory for the list of files (sample below).

2) uses BAPI_IPAK_GETDETAIL and then BAPI_IPAK_CHANGE to change the infopackage file parameter for each infopackage in the chain. (these function modules are not supported in a BW/4HANA system, for that you'll need a different solution.)

3) schedules the chain using function RSPC_API_CHAIN_START and monitors it using RSPC_API_CHAIN_GET_STATUS in a wait loop until it's done, then moves onto the next group of files until all loaded, report results back to calling chain...


For reading the files from a file system you can wrap a class or function around these kernel functions and return a list:

*Prepare for reading from file system
    call 'C_DIR_READ_FINISH'             " just to be sure
           id 'ERRNO'  field ls_file-errno
           id 'ERRMSG' field ls_file-errmsg.

*Evaluate whether file exists for file pattern in directory
    call 'C_DIR_READ_START'
           id 'DIR'    field id_longpath
           id 'FILE'   field '*.*'
           id 'ERRNO'  field ls_file-errno
           id 'ERRMSG' field ls_file-errmsg.
  if sy-subrc ne 0.
*...exception handling: nothing found
  endif.

*Read all files matching file pattern
    do.
      call 'C_DIR_READ_NEXT'
           id 'TYPE'   field ls_file-type
           id 'NAME'   field ls_filen-filename
           id 'ERRNO'  field ls_file-errno
           id 'ERRMSG' field ls_file-errmsg.
      if sy-subrc ne 0 .
        exit.
      endif.
*...add code to filter list according to requirements