03-25-2008 4:04 AM
Hello Friends,
I have a unix directory like this "/usr/sap/psda/sap2bnin/dsas/" which is having different files. I want to get all the filenames from this directory and store it in internal table for my further use. What is the best way to do this.
Waiting for your reply.
Thanks,
Shreekant
03-25-2008 4:14 AM
Hi Shreekant Rangrej
Please see the following sample program for viewing the application server file system and reading the files into your ABAP program.
report ztest_read_file.
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.
format hotspot on.
write:/ ifile-name.
hide ifile-name.
format hotspot off.
endloop.
at line-selection.
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.
also look at below threads
Hope it will solve your problem
Reward points if useful...
Thansk & Regards
ilesh 24x7
03-25-2008 4:14 AM
Hi Shreekant Rangrej
Please see the following sample program for viewing the application server file system and reading the files into your ABAP program.
report ztest_read_file.
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.
format hotspot on.
write:/ ifile-name.
hide ifile-name.
format hotspot off.
endloop.
at line-selection.
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.
also look at below threads
Hope it will solve your problem
Reward points if useful...
Thansk & Regards
ilesh 24x7
02-02-2011 5:07 AM
Thanks a Lot ILESH. I am sure your reply has helped a lot many Guys, although the post is quite Old. It helped me too.
02-08-2011 11:16 AM
03-25-2008 4:18 AM
Hi,
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.
WRITE : ifile-
ENDLOOP.
03-25-2008 4:57 AM
Hi Shreekanth,
The FM 'RZL_READ_DIR_LOCAL' does not work in Unix application server but it works in windows NT application server.
For Unix ,U have to use some unix os commands to read those files from the server.