02-12-2008 3:36 PM
Hi Abapers,
I want to read all the files residing in a particular directory of application server. Is there any function module which gives the list of files in a directory of application server.
Kindly help me.
Regards,
Radhika.
02-12-2008 3:40 PM
https://forums.sdn.sap.com/click.jspa?searchID=8786023&messageID=4856627
Here is the code..
Retrieving the list of files in the given directory
CALL FUNCTION 'RZL_READ_DIR_LOCAL'
EXPORTING
NAME = PA_AFILE " Directory Path
TABLES
FILE_TBL = T_AFILES " All files...
EXCEPTIONS
ARGUMENT_ERROR = 1
NOT_FOUND = 2
OTHERS = 3.
IF SY-SUBRC 0.
* If it is run in background
IF SY-BATCH EQ C_TRUE.
WRITE: /5 'Directory cannot be opened'(039).
FL_FALSE = C_TRUE.
ELSE.
MESSAGE S000(ZZ_PA) WITH 'Directory cannot be opened'(039).
FL_FALSE = C_TRUE.
ENDIF.
02-12-2008 4:25 PM
*My question is not answered, my requirement is:
say if there are 10 files in below directory of application server
/usr/sap/interfaces/central/data, then i need to read all these files.... how can i achieve this.*
02-12-2008 4:28 PM
02-12-2008 4:31 PM
my above post will help you in getting the list of all the files..
reading all the files.. I doubts if its possible... in the link provided in above post.. try playing with the mask.. But I am not sure if it works..
02-12-2008 8:22 PM
Use FM SUBST_GET_FILE_LIST to get a list of all the files under the directory. Then loop on this list files and read each one of them.
Use statements OPEN DATASET, READ, and CLOSE DATASET.
04-16-2022 9:53 AM
Hello. If I am combining csv files but want to remove header lines ie adding data from second row of all files ... how to do it?
02-12-2008 3:43 PM
02-12-2008 3:51 PM
Use the function module SUBST_GET_FILE_LIST to get all the files under a specific directory in the application server.
02-12-2008 8:28 PM
If you would like to read each file under the directory, you would need to use the mentioned function to get all of the names of the files, and then use the DATASET statments to read each file.
report zrich_0001 .
data: begin of itab occurs 0,
rec(1000) type c,
end of itab.
data: wa(1000) type c.
data: p_file type localfile.
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.
concatenate p_path ifile-name into p_file.
clear itab. refresh itab.
open dataset p_file for input in text mode.
if sy-subrc = 0.
do.
read dataset p_file into wa.
if sy-subrc <> 0.
exit.
endif.
itab-rec = wa.
append itab.
enddo.
endif.
close dataset p_file.
loop at itab.
write:/ itab.
endloop.
endloop.
REgards,
RIch Heilman
05-08-2008 3:56 PM
Hi Rich,
I am really sure if the solution to my question is already answered somewhere else.
The requirement is:
If I give a directory path on a application server, I need to list all the files, directories, sub directories, sub files etc... underneeth that.
It should go to the level where there will not be any more directories.
Hope the question is clear!
<removed_by_moderator>
Thank you,
Gayatri.
Edited by: Julius Bussche on Sep 8, 2008 1:05 PM
05-23-2008 2:58 PM
02-13-2008 7:41 AM
hi,
These FM might help you.
EPS_GET_DIRECTORY_LISTING Lists filenames from the application server
TMP_GUI_DIRECTORY_LIST_FILES Lists files and subdirectories
TMP_GUI_READ_DIRECTORY Lists files in a directory
<removed_by_moderator>
Edited by: Julius Bussche on Sep 8, 2008 1:05 PM
07-17-2013 3:37 AM
hi,Runal,
if I use EPS_GET_DIRECTORY_LISTING to get all the filenames from the application server. then I need to get all the data in all of this file. how do I fulfill this? And further, If I want to import the internal table of an abap program into application server, how to fulfill this?
Thanks for your sincere answer.
08-06-2013 12:42 PM
Hi Zhang, you are just responding to a very old post. It would be better to open a new post for a new question and if refer to other posts. However if you look at the post of Rich Heilmann (5 posts above) and replacethe call to RZL_READ_DIR_LOCAL by a call to EPS_GET_DIRECTORY_LISTING you already have the solution.
Regards,
Patrick
05-08-2008 5:26 PM
Hi,
You can use this code:
OPEN DATASET lv_pent FOR INPUT IN binary MODE.
IF sy-subrc = 0.
clear wa_xml.
READ DATASET lv_pent INTO wa_xml.
IF sy-subrc <> 0 or wa_xml is initial.
CLOSE DATASET lv_pent.
EXIT.
ENDIF.
endif.
Regards,
Fernando
05-08-2008 6:29 PM
Hi,
Some directory server FMs:
/SAPDMC/LSM_F4_SERVER_FILE - Shows a popup with list of directories in app server
SUBST_GET_FILE_LIST - Return a list of all files in app server dir to a table
EPS_GET_DIRECTORY_LISTING - Return a list of all files in app server dir to a table
09-08-2008 2:10 PM
Hi
Use "RZL_READ_DIR" Function Module
call function 'RZL_READ_DIR'
exporting
name = p_file " Application server directory
srvname = ' '
tables
file_tbl = lt_file " this internal table having list of file names
exceptions
argument_error = 1
not_found = 2
send_error = 3
system_failure = 4
others = 5.