Tuesday, November 22, 2011 at 1:20 AM |
In SAP ABAP you can read file with open dataset,
The command used to read a file on the application server is as follows.

OPEN DATASET ... FOR INPUT

Please see example code below.

REPORT YSANTO_12 .

data: lv_fname(100),
       &nbsp   lv_msg like sy-msgv1.

data: begin of gi_data occurs 0,
      &nbsp  &nbsp  &nbsp   txt(255),
       &nbsp   end of gi_data.


lv_fname = '/home/data/data.txt'.

open dataset lv_fname for input message lv_msg in text mode encoding default.

if sy-subrc = 0.
    &nbsp do.
    &nbsp   read dataset lv_fname into gi_data-txt.
    &nbsp   if sy-subrc <> 0.
    &nbsp       &nbsp   exit.
    &nbsp   endif.
    &nbsp   append gi_data.
    &nbsp   clear gi_data.
    &nbsp enddo.
else.
    &nbsp   write 'File does not exist!'.
endif.

close dataset lv_fname.
Posted by Shanto Labels:

0 comments: