Friday, 19 April 2013

Files in a folder...

Not being a proper basis geek, I often get confused with file string formatting to describe locations and so on. Forward/back slashes directories, folders etc. 
On our project, a third party is FTPing into our SAP system, then telling us via a PI service where that folder is.
I can read the files using good olde "Open dataset" statement, but I need to know what they are first.

Here's the directory I wanted to read: (Transaction AL11)



Here's my code:


REPORT  YPD_GET_FILES_LIST.
data: dir_list type TABLE OF EPSFILI,
      file type epsfili,
      dir_name type EPSF-EPSDIRNAM.

dir_name = '/usr/sap/MIE/EB'.
CONCATENATE dir_name '/LCAPreRelease/EngData/GB/A/3000-3999' into dir_name.


CALL FUNCTION 'EPS2_GET_DIRECTORY_LISTING'
  EXPORTING
    DIR_NAME                     = DIR_NAME
  TABLES
    DIR_LIST                     = 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.

LOOP AT DIR_list into file.
  write:/ file-name.
endloop.


So the thing to notice is that the function module expects EXACTLY what you see in transaction AL11

(*EDIT - I switched out EPS_GET for EPS2_GET as it allows 200char filenames, rather than the pansy 60 that EPS_GET allows! :) )

No comments:

Post a Comment