2007 Apr 10 5:03 PM
I have to read a text file into my data objects until the end of file. I need help with this syntax
do
read dataset file into strfile
while end of file ?
2007 Apr 10 5:06 PM
hi
use the following code:
do.
read dataset <datasetname> into s_string.
if sy-subrc ne 0.
exit.
endif.
.
.
.
.
enddo.
Please award points if helpful.
Prabhas
I have to read a text file into my data objects until the end of file. I need help with this syntax
do
read dataset file into strfile
while end of file ?
2007 Apr 10 5:06 PM
hi
use the following code:
do.
read dataset <datasetname> into s_string.
if sy-subrc ne 0.
exit.
endif.
.
.
.
.
enddo.
Please award points if helpful.
Prabhas
2007 Apr 10 5:07 PM
2007 Apr 10 5:08 PM
Hi Megan,
Small corection to the code.
read dataset <filename> for input in text mode encoding default.
do.
read dataset <filename> into itab-data.
if sy-subrc = 0.
append itab.
clear itab.
else.
exit.
endif.
enddo.
close dataset <filename>.Regards,
Ravi
2007 Apr 10 5:09 PM
You have first open the file in text mode
OPEN DATASET myfile IN TEXT MODE ENCODING DEFAULT.
After that you introduce the loop to read the file record by record and if read fails you exit.
DO.
READ DATASET myfile INTO myrecordstructure.
IF SY-SUBRC <> 0.
*-- End of file reached
EXIT.
ENDIF.
......
..... rest of the processing with the current record
ENDDO.
2007 Apr 10 5:15 PM
Hi Megan,
Hope this code helps you.
Start-of-selection.
open dataset fname for input in text mode.
if sy-subrc <> 0.
message s999(z1) with 'File not found or cannot be opened'.
stop.
endif.
do.
read dataset fname into i_upload.
if sy-subrc <> 0.
exit.
endif.
append i_upload.
clear i_upload.
enddo.
close dataset fname.
Thanks,
Srinivas
2007 Apr 10 6:30 PM
Hi,
Please try this.
* Retrieve Data file from Application server(Upload from Unix)
DATA: i_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
OPEN DATASET i_file FOR INPUT IN TEXT MODE.
IF sy-subrc NE 0.
MESSAGE e999(za) WITH 'Error opening file' i_file.
ENDIF.
DO.
* Reads each line of file individually
READ DATASET i_file INTO wa_datatab.
* Perform processing here
* .....
ENDDO.
Regards,
Ferry Lianto
2007 Apr 10 6:31 PM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |