‎2005 Nov 15 1:30 PM
Hi,
I have an internal table with different fields:Material, Grade, Country of origin, Region and Qty. I need to aggregate the data per grade, country and region...Can anyone help?
‎2005 Nov 15 1:32 PM
HI Mel,
Use the statement
collect itab.
in your code to get the aggregate as i can see all the fields other than quantity are non numeric.
Regards,
Ravi
‎2005 Nov 15 1:34 PM
Hi ravi,
but the thing is I need to aggregate based on the 4 fields I mentionned....
‎2005 Nov 15 1:37 PM
what you probably need is the use of the AT NEW control breaks in the loop .. endloop of your internal table..
Good Luck
Suresh Datti
‎2005 Nov 15 1:37 PM
COLLECT will do exactly that as long as all your character type fields are same, it will sum up all your number fields.
So instead of doing an APPEND itab, do a COLLECT itab.
Srinivas
‎2005 Nov 15 1:36 PM
Mel,
use
loop at itab.
At new grade.
like that maintain all ur conditions and do collect itab.
Don't forget to sort the itab first.
‎2005 Nov 15 1:47 PM
Hi,
This is sample code where you do an aggregate.
As per requirement, you read with the field you need the aggregate.
loop....
read table research_recap with key rcode = wrk_rec-rcode.
if sy-subrc = 0.
research_recap-reason_cnt = research_recap-reason_cnt + lv_cnt.
research_recap-ord_vol = research_recap-ord_vol + lv_ord_vol.
research_recap-inv_vol = research_recap-inv_vol + lv_inv_vol.
research_recap-netwr = research_recap-netwr + lv_netwr.
modify research_recap index sy-tabix.
else.
research_recap-reason_cnt = lv_cnt.
research_recap-ord_vol = lv_ord_vol.
research_recap-inv_vol = lv_inv_vol.
research_recap-netwr = lv_netwr.
append research_recap.
clear : research_recap.
endif.
endloop.
Regards,
Sailaja.
‎2005 Nov 15 2:10 PM
Hi,
i was wondering...how do u do AT NEW for different fields since I need to aggreagate per Grade, Country and region and not just by one field.
‎2005 Nov 15 2:40 PM
Hi Mel,
To make the aggregation based on three fileds,
Make these the first three fields in the internal table.
You should sort the internal table by the three fields.
Then use <b>at end of</b> for the third field.
sort itab bye grade country region.
loop at itab.
at end of region.
collect itab.
endat.
endloop.
Regards,
Ravi
‎2005 Nov 15 2:16 PM
SELECT Material, Grade, Country of origin, Region
SUM( Qty ) AS bdmng
INTO CORRESPONDING FIELDS OF itab
FROM <table>
GROUP BY Material, Grade, Country of origin, Region .
hope this will work.
Allot points if your query solved.
‎2005 Nov 15 2:24 PM
Sorry Vinod but your query is not working!!!
‎2005 Nov 15 2:34 PM
Hi mel,
Try other alternatives with the same query like use QTY instead of BDMNG...
What I sent you is a pseudo code but the idea is the same . Check out as it worked for me many times.
Warm regards,
Vinod.
‎2005 Nov 15 3:19 PM
Hi use the following coe.
sort itab by grade.
loop at itab.
collect itab.
endloop.
the above code will help u to achive ur functionality.
satish
‎2005 Nov 15 4:29 PM
Mel,
Can you please explain why COLLECT is not working? What is the structure of your internal table? May be that will help us to see why COLLECT is not working for you. COLLECT should be done when you are building the internal table, not when you already have the records in the table. Also, if you are selecting from database into this table directly, then the collect will not work. Is this the case with your internal table?
Please let us know.
Srinivas