‎2014 Feb 21 2:26 PM
Hi ABAP gurus,
I am new to ABAP and practicing it. I have written the following code which is throwing the error "IT3 cannot be converted to a character type field"
The code written is as follows ,
data: begin of it3 occurs 3,
c1 type i,
c2 type i,
end of it3.
it3-c1 = 11.
it3-c2 = 12.
append it3 to it3.
it3-c1 = 21.
it3-c2 = 22.
append it3 to it3.
it3-c1 = 31.
it3-c2 = 32.
append it3 to it3.
loop at it3.
write: / it3, 'sy-tabix=', sy-tabix.
endloop.
Please help me in resolving the issue.
‎2014 Feb 21 4:43 PM
Hi Soumya,
The mistake is that in the WRITE statement you have to specify the single components of the structure if it contains numbers (non-char-like).
Also, you are using a quite outdated form of ABAP programming, namely internal table with header line, and not using a work area or field-symbol in the LOOP.
A little bit more up-to-date would be:
types: begin of ltype_3,
c1 type i,
c2 type i,
end of ltype_3.
data: it3 type standard table of ltype_3 initial size 3,
wa3 type ltype_3.
wa3-c1 = 11.
wa3-c2 = 12.
append wa3 to it3.
"...
loop at it3 into wa3.
write:/ wa3-c1, wa2-c2, 'sy-tabix=', sy-tabix.
endloop.
If the structure of ltype_3 becomes more complex, instead of LOOP ... INTO one should use LOOP ... ASSIGNING.
Best Regards, Randolf
‎2014 Feb 21 4:43 PM
Hi Soumya,
The mistake is that in the WRITE statement you have to specify the single components of the structure if it contains numbers (non-char-like).
Also, you are using a quite outdated form of ABAP programming, namely internal table with header line, and not using a work area or field-symbol in the LOOP.
A little bit more up-to-date would be:
types: begin of ltype_3,
c1 type i,
c2 type i,
end of ltype_3.
data: it3 type standard table of ltype_3 initial size 3,
wa3 type ltype_3.
wa3-c1 = 11.
wa3-c2 = 12.
append wa3 to it3.
"...
loop at it3 into wa3.
write:/ wa3-c1, wa2-c2, 'sy-tabix=', sy-tabix.
endloop.
If the structure of ltype_3 becomes more complex, instead of LOOP ... INTO one should use LOOP ... ASSIGNING.
Best Regards, Randolf
‎2014 Feb 21 5:46 PM
Hi,
Please try the following
types: begin of ty_3,
c1 type i,
c2 type i,
end of ty_3,
tt_3 type standard table of ty_3.
data: it3 type tt_3, "Internal table
wa3 type ty_3. "Work area
wa3-c1 = 11.
wa3-c2 = 12.
append wa3 to it3.
wa3-c1 = 21.
wa3-c2 = 22.
append wa3 to it3.
wa3-c1 = 31.
wa3-c2 = 32.
append wa3 to it3.
loop at it3 into wa3.
write: / wa3-c1, wa3-c2, 'sy-tabix=', sy-tabix.
endloop.
Note: The error in your code was because you were trying to display the work area directly in your WRITE statement within the LOOP. You need to write individual fields rather than the entire work area of the internal table.
Regards,
Mayur Priyan. S
‎2014 Feb 21 6:32 PM
Thanks Randolf and Mayur for your help.