I need to get a listing of a server-side directory inside SAP. How do I achieve this in ABAP? Are there any built-in SAP functions I can call?
Ideally I want a function which I can pass a path as input, and which will return a list of filenames in an internal table.
Open the transaction “os01”. Click on “Application server”. The host name is now displayed. If the IP address is not yet displayed, also click on “Change View”.
data: ifile type table of salfldir with header line. parameters: p_path type salfile-longname default '/usr/sap/TST/DVEBMGS01/data/'. call function 'RZL_READ_DIR_LOCAL' exporting name = p_path tables file_tbl = ifile exceptions argument_error = 1 not_found = 2 others = 3. loop at ifile.
EPS2_GET_DIRECTORY_LISTING
does the same thing as EPS_GET_DIRECTORY_LISTING
BUT retunrs the file names up to 200 chars!
Call function RZL_READ_DIR_LOCAL:
FUNCTION RZL_READ_DIR_LOCAL.
*"----------------------------------------------------------------------
*"Lokale Schnittstelle:
*" IMPORTING
*" NAME LIKE SALFILE-LONGNAME
*" TABLES
*" FILE_TBL STRUCTURE SALFLDIR
*" EXCEPTIONS
*" ARGUMENT_ERROR
*" NOT_FOUND
*"----------------------------------------------------------------------
Place the path in the NAME import parameter, and then read the directory listing from FILE_TBL after it returns.
RZL_READ_DIR_LOCAL can handle normal local paths as well as UNC paths.
The only downside is it only gives you access to the first 32 chars of each filename. However, you can easily create a new function based on the RZL_READ_DIR_LOCAL code, and change the way the C program output is read, as the first 187 characters of each filename are actually available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With