‎2008 Jun 12 6:26 AM
Hi guys,
i have data like this:
data1 data2 data3
1001(type c) 2 2568 (type c)
1001(type c) 3 2569 (type c)
For every same entry in data1, i have to sum the correponding data in data2. how can it be done?
‎2008 Jun 12 6:45 AM
hi there
i had gone through a similar problem.collect will not work for your case since there are 2 non-numeric fields...
the foll worked for me...
loop at itab.
at new itab-field1.
sum = 0.
break.
endat.
sum = sum + itab-field2.
write 😕 sum.
endloop.
everytime the field1 value changes, the loop breaks and control goes to loop-at command. this way, for same field1 values, sum will get calculated and stored in sum.
i hope it helps...
reward if helpful
regards
niharika
‎2008 Jun 12 6:28 AM
‎2008 Jun 12 6:29 AM
u can either use collect statement or control break statements like AT END OF...ENDAT.
pk
‎2008 Jun 12 6:35 AM
hi prashant,
PS that collect wont work properly as there are two fields of type c.
anything else??
‎2008 Jun 12 6:32 AM
loop at itab.
at new field1.
sum.
write itab-field1.
write itab-field2.
endat.
endloop.
‎2008 Jun 12 6:35 AM
‎2008 Jun 12 6:45 AM
hi there
i had gone through a similar problem.collect will not work for your case since there are 2 non-numeric fields...
the foll worked for me...
loop at itab.
at new itab-field1.
sum = 0.
break.
endat.
sum = sum + itab-field2.
write 😕 sum.
endloop.
everytime the field1 value changes, the loop breaks and control goes to loop-at command. this way, for same field1 values, sum will get calculated and stored in sum.
i hope it helps...
reward if helpful
regards
niharika
‎2008 Jun 12 6:52 AM
Hi Prem..
use at-new .... endat with the field name(Data1) and take a temp variable to calculate the DATA2.
Hope this info will work.
Reward Points if helpful
Regards
Karan
‎2008 Jun 12 6:55 AM
thanks all....
query solved.... points rewarded to helpful ans...
‎2008 Jun 12 7:02 AM
Hi Prem,
First sort internal table by data1 field.
Using
sort itab by data1.
then use this code.
loop at itab.
at new itab-data1.
sum = 0.
break.
endat.
sum = sum + itab-data2.
write 😕 sum.
endloop.