07-15-2008 4:44 PM
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.
07-15-2008 4:48 PM
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.
07-15-2008 4:48 PM
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.
07-15-2008 4:52 PM
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
07-15-2008 4:55 PM
07-15-2008 5:05 PM
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
07-16-2008 10:56 AM