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

open dataset

Former Member
0 Likes
620

Hi Experts,

I have a directory in the application server .

I have some list of files in that directory.

So i have to read the directory first and i have to process the file one by one and i have to upload the data in the file into SAP.This i have to do in background.

Can any body tell me some suggessions on this?

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
591

Please take a look at this application server file browser program. You can use this for your requirement, the only difference here is that it provides a list for the user to choose which file to upload, you can simply modify it for your needs.



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
591

Hi,

Thanks for reply.But my program will run in back ground.

So there won't be any selection-screen in my pgm.

So in that FM if i hardcode the path will it run background?

Read only

0 Likes
591

Yes. Again you will need to modify the examples a little.

Regards

Rich Heilman

Read only

0 Likes
591

Just change the parameters statement to this.

<b>data:</b> p_path type salfile-longname
                   <b> value</b> '/usr/sap/TST/DVEBMGS01/data/'.

Regards,

Rich Heilman

Read only

Laxmana_Appana_
Active Contributor
0 Likes
591

Hi,

use FM : 'RZL_READ_DIR_LOCAL' to read files on the application server.

check this code :

PARAMETER: p_fdir            type pfeflnamel DEFAULT '/usr/sap/tmp'.

data: begin of it_filedir occurs 10.
        include structure salfldir.
data: end of it_filedir.



START-OF-SELECTION.
* Get Current Directory Listing for OUT Dir
  call function 'RZL_READ_DIR_LOCAL'
       exporting
            name     = p_fdir
       tables
            file_tbl = it_filedir.

* List of files are contained within table it_filedir
  loop at it_filedir.
   clear :i_xcontent.
   refresh :i_xcontent.
open dataset it_filedir-file for input in text mode.
  do.
    read dataset it_filedir-file into ls_xcontent-line.
    if sy-subrc eq 0.
      append ls_xcontent to i_xcontent.
    endif.
  enddo.
close dataset it_filedir-file.

*Update table with internal table data 
    modify ztable from table i_xcontent.


  endloop.

Regards

Appana