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

How to use READ DATA SET statement?

Former Member
0 Likes
13,007

I have asked last time how to use Read Dataset statement,My thread was closed I don't know the reason as everybody has replied for OPEN DATA SET but My question is How to use READ DATA SET statement inside OPEN DATA SET.,AS I have transferred one file in ftp and i want to read it again using READ DATA SET so how i can do so?

1 ACCEPTED SOLUTION
Read only

kamesh_g
Contributor
0 Likes
4,985

Hi

     open dataset <file> for input in text mode encoding default message lw_mesg.
  if sy-subrc = 0.
    do.
      read dataset <file> into lw_buffer.  "lw_buffer string type
      if sy-subrc <> 0.
        close dataset  <file>.
        exit.
      endif.
* Append the record
      if lw_buffer is not initial.
        ls_data_raw-data  = lw_buffer.   "here ls_data _raw is a table type consists of DATA as field of   

                                                       "type string
        append ls_data_raw to lt_data_raw.
        clear: ls_data_raw.
      endif.
    enddo.
    close dataset <file>.
  else.
    messagw E<num> with lw_mesg" No data found
  endif.

4 REPLIES 4
Read only

kamesh_g
Contributor
0 Likes
4,986

Hi

     open dataset <file> for input in text mode encoding default message lw_mesg.
  if sy-subrc = 0.
    do.
      read dataset <file> into lw_buffer.  "lw_buffer string type
      if sy-subrc <> 0.
        close dataset  <file>.
        exit.
      endif.
* Append the record
      if lw_buffer is not initial.
        ls_data_raw-data  = lw_buffer.   "here ls_data _raw is a table type consists of DATA as field of   

                                                       "type string
        append ls_data_raw to lt_data_raw.
        clear: ls_data_raw.
      endif.
    enddo.
    close dataset <file>.
  else.
    messagw E<num> with lw_mesg" No data found
  endif.

Read only

arivazhagan_sivasamy
Active Contributor
0 Likes
4,985

Hi Ronak,

To write a file in application server, you have to use

Open dataset filename for output


then


Transfer itab to filename.


Now you can able to see the records in application server using TCode AL11.


Then,


To read a file in application server, you have to use..


Open dataset filename for input.


Then


Do.


Read dataset filename into your internal table.


Enddo.




Arivazhagan S

Read only

Former Member
0 Likes
4,985

Hi Ronak,

Please check the below code for read dataset inside  open dataset.

DATA: file TYPE string VALUE `flights.dat`,

wa TYPE spfli.

FIELD-SYMBOLS <hex_container> TYPE x.


OPEN DATASET file FOR INPUT IN BINARY MODE.

ASSIGN wa TO <hex_container> CASTING.

DO.

READ DATASET file INTO <hex_container>.

IF sy-subrc = 0.

WRITE: / wa-carrid,

wa-connid,

wa-countryfr,

wa-cityfrom,

wa-cityto,

wa-fltime,

wa-distance.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET file.

Thanks

Bharathi

Read only

Former Member
0 Likes
4,985

Hi Ronak,

Once open dataset statment is success.

use the below statment

READ DATASET FNAME INTO TEXT2 LENGTH LENG.

Here it reads the data from application server file fname and places in varaiable text2

Please use below link for further details:

http://help.sap.com/saphelp_470/helpdata/EN/fc/eb3d42358411d1829f0000e829fbfe/content.htm

Regards,

Vineesh.