Application Development and Automation 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: 
Read only

Read all Files from a Folder on Server

Former Member
0 Likes
11,628

Hi,

Can anyone help me in finding if there's any way to read all files in a folder on the server?Any Function module or anything.

Thanks

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
4,562

On App server? Try this sample program.



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.
  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.

Regards,

Rich Heilman

Hi,

Can anyone help me in finding if there's any way to read all files in a folder on the server?Any Function module or anything.

Thanks

7 REPLIES 7
Read only

Former Member
4,562

Hi

Try the method DIRECTORY_LIST_FILES of class CL_GUI_FRONTEND_SERVICES for Presentation server or/and fm SUBST_GET_FILE_LIST for Application server

Max

Read only

Former Member
0 Likes
4,562

hi sirisha,

check the FM 'RZL_READ_DIR_LOCAL'

hope this helps,

do reward if it helps,

priya.

Read only

RichHeilman
Developer Advocate
Developer Advocate
4,563

On App server? Try this sample program.



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.
  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.

Regards,

Rich Heilman

Read only

0 Likes
4,562

Problem with this FM is that it can only have 32 character filename, is there any other FM which can help choose files having long filenames?

Read only

4,562

amnsrivastava please, ask your own question

Read only

Former Member
0 Likes
4,562

Thanks for all your replies.

Points awarded

Read only

Former Member
0 Likes
4,562

Wrong thread.

Edited by: Moisés Lorenzo on Jul 7, 2009 1:01 PM