‎2008 Apr 30 7:41 AM
Hi all,
i have two internal tables:
1. structure:
line: workarea e.g. 1 2 3
2 3 6
2. structure:
3000
6000
2000
Now should be build a sum.
Look at structure 1. For the first sum we need entry 1, 2 and 3 from structure 2. (3000 + 6000 + 2000 = 11000)
The next sum is calculated by the entry 2, 3 and 6 .......
Any ideas how to do this?
regards
‎2008 Apr 30 7:47 AM
itab1 contains : 1 2 3; 2 3 6
loop at itab1.
sum = 0.
read table itab2 index wa-itab1-field1 into valie.
sum = sum + value.
read table itab2 index wa-itab1-field2 into valie.
sum = sum + value.
read table itab2 index wa-itab1-field3 into valie.
sum = sum + value.
write : sum.
endloop
‎2008 Apr 30 7:55 AM
Hi,
Check the below code.
data: begin of itab occurs 0,
num1 type i,
num2 type i,
num3 type i,
end of itab.
data: begin of itab1 occurs 0,
num1 type i,
num2 type i,
num3 type i,
end of itab1.
data: v_tabix type i,
v_first_sum type i,
v_second_sum type i.
itab-num1 = 1.
itab-num2 = 2.
itab-num3 = 3.
append itab.
itab-num1 = 2.
itab-num2 = 3.
itab-num3 = 6.
append itab.
itab1-num1 = 3000.
itab1-num2 = 6000.
itab1-num3 = 2000.
append itab1.
itab1-num1 = 5000.
itab1-num2 = 4000.
itab1-num3 = 1000.
append itab1.
loop at itab.
clear: v_first_sum, v_second_sum.
v_tabix = sy-tabix.
v_first_sum = itab-num1 + itab-num2 + itab-num3.
write:/ 'Sum of record ', v_tabix, '= ', v_first_sum.
read table itab1 index v_tabix.
if sy-subrc = 0.
v_second_sum = itab1-num1 + itab1-num2 + itab1-num3.
write:/ 'Sum of record ', v_tabix, '= ', v_second_sum.
endif.
endloop.
Edited by: Velangini Showry Maria Kumar Bandanadham on Apr 30, 2008 8:56 AM
‎2008 Apr 30 7:57 AM
hi
check this code
data:
begin of itab,
n1 type i,
n2 type i,
n3 type i,
end of itab.
begin og itab1,
num type i,
end of itab1,
sum type i.
loop at itab.
loop at itab1 where sy-tabix = itab-n1
or sy-tabix = itab-n2
or sy-tabix = itab-n3
sum = sum + itab1-num.
endloop.
write:/ 'sum =' , sum.
clear sum.
endloop.