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

Sample code to modify an internal table column?

Former Member
0 Likes
2,016

We have an internal table itab which looks like to have the following content:

A---B---C

1----3----

2----2----

We would like to get the column C value in this internal table itab by summing Column A and Column B, and then fill C column values into this internal table. We know that the program would looks like:


Loop itab into wa_itab.
  wa_itab-C = wa_itab-A + wa_itab-B.
End Loop.

Modify itab.

We know that the above program could not be right. Could ABAP experts here complete/correct the above program?

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 8, 2008 1:04 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,454

This will Work fine.

>Loop itab into wa_itab.

> wa_itab-C = wa_itab-A + wa_itab-B.

>Modify itab index sy-tabix.

>End Loop.

OR

>field symbols: <wa_itab> type itab.

>Loop itab assigning <wa_itab>.

> <wa_itab>-C = <wa_itab>-A + <wa_itab>-B.

>endloop.

8 REPLIES 8
Read only

Former Member
0 Likes
1,455

This will Work fine.

>Loop itab into wa_itab.

> wa_itab-C = wa_itab-A + wa_itab-B.

>Modify itab index sy-tabix.

>End Loop.

OR

>field symbols: <wa_itab> type itab.

>Loop itab assigning <wa_itab>.

> <wa_itab>-C = <wa_itab>-A + <wa_itab>-B.

>endloop.

Read only

0 Likes
1,454

hi Amandeep,

We use your code below:

Loop itab into wa_itab.

wa_itab-C = wa_itab-A + wa_itab-B.

Modify itab index sy-tabix.

End Loop.

But when activating the code, get the following error:

".", "AT ...", "AT SCREEN" or "AT ... VERSION ... ." expected after Loop.

What would be the reason and how to have it resolved?

Thanks!

Read only

0 Likes
1,454

It will be


Loop AT itab into wa_itab

a®

Read only

0 Likes
1,454

hi Amandeep,

Unfortunately the "Modify itab index sy-tabix." statement make all itab contents blank! Do you know what's going on?

Thanks!

Loop itab into wa_itab.

wa_itab-C = wa_itab-A + wa_itab-B.

Modify itab index sy-tabix.

End Loop.

Read only

0 Likes
1,454

Try this way


Modify itab from wa_itab index sy-tabix.

a®

Read only

Former Member
0 Likes
1,454

Kevin,

just entered the modify statement inside the loop.

It will work

make sure while modifying pass the index number. Then the system will update the index

Cheers,

Chidanand

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 8, 2008 1:17 PM

Read only

Former Member
0 Likes
1,454

Hi,

What is your requirement exactly, any how please see the below code it is working.

I got the output also.

data: begin of itab occurs 0,

a type i,

b type i,

c type i,

end of itab.

itab-a = '5'.

itab-b = '6'.

append itab.

clear itab.

itab-a = '2'.

itab-b = '3'.

append itab.

clear itab.

loop at itab .

itab-c = itab-a + itab-b.

modify itab.

endloop.

loop at itab.

write:/ itab-a, itab-b, itab-c.

endloop.

Thanks

Ganesh

Read only

GrahamRobbo
SAP Mentor
SAP Mentor
0 Likes
1,454

Hi Kev,

my suggestion


  DATA: itab TYPE TABLE OF mystruct,
        lref TYPE REF TO mystruct.

  LOOP AT itab REFERENCE INTO lref.
    lref->c = lref->a + lref->b.
  ENDLOOP.

Cheers

Graham Robbo