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: 

Get files from directory in application server

Former Member
0 Kudos

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.

17 REPLIES 17

former_member156446
Active Contributor
0 Kudos

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.

0 Kudos

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

0 Kudos

Its possible through Open dataset statement

thnkx

0 Kudos

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

0 Kudos

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.

0 Kudos

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?

Former Member
0 Kudos

you can use the OPEN DATASET Statement

thnkx

bhanu

Former Member
0 Kudos

Use the function module SUBST_GET_FILE_LIST to get all the files under a specific directory in the application server.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

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

0 Kudos

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

0 Kudos

Superb! Anna.

ur code is working successfully.

Thanks a lot.

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

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

rodrigo_paisante3
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.