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

Need help in resolving error in program

Former Member
0 Likes
436

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.

1 ACCEPTED SOLUTION
Read only

former_member184455
Active Participant
0 Likes
407

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

3 REPLIES 3
Read only

former_member184455
Active Participant
0 Likes
408

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

Read only

mayur_priyan
Active Participant
0 Likes
407

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

Read only

Former Member
0 Likes
407

Thanks Randolf and Mayur for your help.