Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting fine names from unix directory

former_member248300
Participant
0 Kudos

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

1 ACCEPTED SOLUTION

former_member387317
Active Contributor
0 Kudos

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

5 REPLIES 5

former_member387317
Active Contributor
0 Kudos

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

0 Kudos

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.

0 Kudos

try FM F4_DXFILENAME_TOPRECURSION

Former Member
0 Kudos

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.

former_member708410
Contributor
0 Kudos

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.