Get the contents of a Application Server directory
Asked Answered
T

5

11

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.

Trawler answered 30/9, 2008 at 12:58 Comment(0)
B
3

After reading the answers of Chris Carrthers and tomdemuyt I would say:

1) Use RZL_READ_DIR_LOCAL if you need simple list of filenames.

2) EPS_GET_DIRECTORY_LISTING is more powerfull - it can also list subdirectories.

Thanks You both!

With best Regards Niki Galanov

Brandenbrandenburg answered 14/5, 2009 at 8:13 Comment(1)
The disadvantage of EPS_GET_DIRECTORY_LISTING is that you need pretty extensive SAP authorization as it's part of the Transport system (TMS) and usually only given to Admins.Maffick
M
7

EPS2_GET_DIRECTORY_LISTING does the same thing as EPS_GET_DIRECTORY_LISTING BUT retunrs the file names up to 200 chars!

Micrography answered 24/11, 2011 at 9:57 Comment(1)
Bless you, sir! Was looking for one all over the place that could take filenames larger than 40 characters. This solved my problem.Upholster
T
5

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.

Trawler answered 3/10, 2008 at 0:59 Comment(3)
Does this read a directory on the server or on the Client? DIR_LOCAL sounds like it is client specific ...Brout
RZL_READ_DIR_LOCAL returns sub-directories as well as filenames. How to separate directories from files ?Ruffle
Sorry @Ruffle I no longer have access to SAP so I'm not sure.Trawler
E
3

the answer is calling function module EPS_GET_DIRECTORY_LISTING. DIR_NAME -> Name of directory FILE_MASK -> Pass '*' to get all files.

Note: This does not deal with really large file names (80 characters+), it truncates the name.

Ema answered 2/10, 2008 at 14:49 Comment(1)
Thanks, I didn't know about that function, but it doesn't seem to work with UNC paths, which I need.Trawler
B
3

After reading the answers of Chris Carrthers and tomdemuyt I would say:

1) Use RZL_READ_DIR_LOCAL if you need simple list of filenames.

2) EPS_GET_DIRECTORY_LISTING is more powerfull - it can also list subdirectories.

Thanks You both!

With best Regards Niki Galanov

Brandenbrandenburg answered 14/5, 2009 at 8:13 Comment(1)
The disadvantage of EPS_GET_DIRECTORY_LISTING is that you need pretty extensive SAP authorization as it's part of the Transport system (TMS) and usually only given to Admins.Maffick
S
1

Take a look at transaction AL11 source code: RSWATCH0 form fill_file_list There you can get all information about files.

Hope this helps!

Slow answered 9/10, 2008 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.