‎2008 Jun 06 7:31 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?
thanks a lot!
rgds,
mark
‎2008 Jun 06 9:19 AM
hi there....
try this out....
loop at itab.
at new itab-data1.
sum = 0.
break.
endat.
sum = sum + itab-date2.
write 😕 sum.
endloop.
here sum is integer type and initialized to zero.
everytime the data1 value changes, the looop breaks and control again goes back to looop at command. this way, for same data1 values, sum will get calculated and stored in sum.
i hope it helps...
do reward if helpful or get back for further assistance.
‎2008 Jun 06 7:35 AM
‎2008 Jun 06 7:37 AM
‎2008 Jun 06 7:39 AM
An example for COLLECT statement
DATA: BEGIN OF LINE,
COL1(3) TYPE C,
COL2(2) TYPE N,
COL3 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE
WITH NON-UNIQUE KEY COL1 COL2.
LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 3.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.
LINE-COL1 = 'def'. LINE-COL2 = '34'. LINE-COL3 = 5.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.
LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 7.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
ENDLOOP.The output is:
1
2
1
abc 12 10
def 34 5
‎2008 Jun 06 9:14 AM
Hi guys,
thnx for your responses,,, but im not sure collect will work for this since i have two fields with type c,,, and i only consider the same entry for data1 to sum up values in data2..
tnx again...
‎2008 Jun 06 9:19 AM
hi there....
try this out....
loop at itab.
at new itab-data1.
sum = 0.
break.
endat.
sum = sum + itab-date2.
write 😕 sum.
endloop.
here sum is integer type and initialized to zero.
everytime the data1 value changes, the looop breaks and control again goes back to looop at command. this way, for same data1 values, sum will get calculated and stored in sum.
i hope it helps...
do reward if helpful or get back for further assistance.