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

Problem in Read Dataset

Former Member
0 Likes
751

Hi Abappers,

I have to read a text file which contains millions of records from the application server and then insert it into the database table.

For this I have used read dataset but not able to convert it into the internal table.

OPEN DATASET lv_fname FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

EXIT.

ELSE.

READ DATASET lv_fname INTO ls_upload1.

IF sy-subrc NE 0.

EXIT.

ELSE.

  • LOOP AT ls_upload1.

SPLIT ls_upload1 AT '|' INTO

ls_toahr-mandt

ls_toahr-sap_object

ls_toahr-object_id

ls_toahr-archiv_id

ls_toahr-arc_doc_id

ls_toahr-ar_object

ls_toahr-ar_date

ls_toahr-del_date

ls_toahr-reserve.

APPEND ls_toahr TO lt_toahr.

CLEAR ls_toahr.

  • ENDLOOP.

ENDIF.

ENDIF.

CLOSE DATASET lv_fname.

Here i am not able to use the loop as read dataset gives workarea not the internal table.

This code reads only the one record.

How to read the file into the Internal table?

Please reply.

Regards.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
715

hi use do ....

do .

read dataset..

enddo.

check this sample example..

OPEN DATASET gd_csvfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

CHECK ( sy-subrc = 0 ).

REFRESH: gt_data_raw.

DO.

READ DATASET gd_csvfile INTO gd_data_raw.

IF ( syst-subrc NE 0 ).

EXIT.

ENDIF.

APPEND gd_data_raw TO gt_data_raw.

ENDDO.

CLOSE DATASET gd_csvfile.

5 REPLIES 5
Read only

Former Member
0 Likes
716

hi use do ....

do .

read dataset..

enddo.

check this sample example..

OPEN DATASET gd_csvfile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

CHECK ( sy-subrc = 0 ).

REFRESH: gt_data_raw.

DO.

READ DATASET gd_csvfile INTO gd_data_raw.

IF ( syst-subrc NE 0 ).

EXIT.

ENDIF.

APPEND gd_data_raw TO gt_data_raw.

ENDDO.

CLOSE DATASET gd_csvfile.

Read only

Former Member
0 Likes
715

You have to use the read dataset statement inside a 'Do' 'Enddo' loop

like this

OPEN DATASET w_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.

READ DATASET w_filename INTO w_string.

IF sy-subrc EQ 0.

--logic

else.

EXIT.

Endif.

ENDDO.

cheers,

Sushil Joshi

Read only

Former Member
0 Likes
715

Rahul,

use read dataset into do enddo .

Amit.

Read only

Former Member
0 Likes
715

Hi Rahul,

Read dataset will return only one record at a time... so what u have to do keep reading from the file until no records are fetched.. the code will be..

do.

read dataset****

if sy-subrc = 0.

split the work area and append it to ur internal table

else.

exit.

endif.

enddo.

since u dont know the exact no. of records that will be there in the file, u have use do-enddo.

after all the records are read, "read dataset" will return a value not equal to 0. then u can exit from the loop..

Reward if useful.

regards,

Anoop

Read only

Former Member
0 Likes
715

Thanks