2008 Apr 08 5:58 PM
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
2008 Apr 08 6:03 PM
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.
2008 Apr 08 6:03 PM
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.
2008 Apr 08 6:56 PM
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!
2008 Apr 08 6:58 PM
2008 Apr 08 8:57 PM
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.
2008 Apr 08 9:12 PM
2008 Apr 08 6:12 PM
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
2008 Apr 08 7:09 PM
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
2008 Apr 10 12:48 AM
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