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

OPEN, READ, CLOSE, TRANSFER DATASET

rciano
Discoverer
0 Likes
2,411

Hi SAP ABAP Gurus,

Please help. Below code is not working.

Error is "<WA>" cannot be converted to the row type of "_TABLE". The reverse is also not possible.

TYPES: BEGIN OF _struct,
_line TYPE string,
END OF _struct.

DATA _table TYPE STANDARD TABLE OF _struct.

FIELD-SYMBOLS <wa> TYPE x.

OPEN DATASET file1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
DO.
READ DATASET file1 INTO <wa>.
IF sy-subrc EQ 0.
APPEND <wa> TO _table.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLEAR _table.
CLOSE DATASET file1.
* DELETE DATASET file1.
ENDIF.

OPEN DATASET file2 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
LOOP AT _table INTO <wa>.
TRANSFER <wa> TO file2.
ENDLOOP.
CLOSE DATASET file2.
ENDIF.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
1,801

<wa> is type X, the line type of _table is _struct, which is a isn't type X. Hence the error. Maybe you should check your course notes or abap help about types in ABAP and conversion of types.

Hi SAP ABAP Gurus,

Please help. Below code is not working.

Error is "<WA>" cannot be converted to the row type of "_TABLE". The reverse is also not possible.

TYPES: BEGIN OF _struct,
_line TYPE string,
END OF _struct.

DATA _table TYPE STANDARD TABLE OF _struct.

FIELD-SYMBOLS <wa> TYPE x.

OPEN DATASET file1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
DO.
READ DATASET file1 INTO <wa>.
IF sy-subrc EQ 0.
APPEND <wa> TO _table.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLEAR _table.
CLOSE DATASET file1.
* DELETE DATASET file1.
ENDIF.

OPEN DATASET file2 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
LOOP AT _table INTO <wa>.
TRANSFER <wa> TO file2.
ENDLOOP.
CLOSE DATASET file2.
ENDIF.

5 REPLIES 5
Read only

muttepawar-2009
Active Participant
0 Likes
1,801

Open dataset file1 for input in text mode encoding default.

if sy-subrc ne 0. write:/ 'Unable to open file:', file1.

else.

do.

read datasset file1 into <wa>.

if sy-subrc ne o.

exit.

else.

append <wa> to _table.

endif.

close dataset file1.

enddo.

endif.

Open dataset file2 for output in text mode encoding default.

if sy-subrc ne 0.

write:/ 'Unable to open file:', file2.

else.

loop at _table.

transfer <wa> to file2.

endloop.

close dataset file2.

endif.

Read only

0 Likes
1,801

It's better to explain what is wrong and why, rather than just correcting without explaining anything

Read only

matt
Active Contributor
1,801

Use the "code" button of the editor when posting code.

Read only

matt
Active Contributor
1,802

<wa> is type X, the line type of _table is _struct, which is a isn't type X. Hence the error. Maybe you should check your course notes or abap help about types in ABAP and conversion of types.

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,801

"code is not working" means nothing, give facts: code is not compiling, there is the following syntax error. Please tell us also the line where the syntax error occurs, rather than letting us reviewing the whole code manually.