‎2009 Dec 26 7:13 AM
Hi,
How can I summarize an internal table? Example being that using a SELECT statement I have obtained the Open Requisitions from table EBAN and moved it into an Internal table wa_itab.
DATA: BEGIN OF wa_itab OCCURS 0,
matnr LIKE marc-matnr, "Material
werks LIKE marc-werks, "Plant
banfn LIKE eban-banfn, "Purchase Requisition
menge LIKE eban-menge, "Quantity Requested
meins LIKE eban-meins, "Unit of Measure
bsmng LIKE eban-bsmng, "Quantity Ordered
opqty LIKE eban-menge, "Open Quantity
lfdat LIKE eban-lfdat, "Delivery Date
day TYPE i, "Delivery Date Day
month TYPE i, "Delivery Date Month
year(4) TYPE n, "Delivery Date Year
qtyls LIKE eban-menge, "Quantity Less Than Current Month
qty01 LIKE eban-menge, "Quantity 1
qty02 LIKE eban-menge, "Quantity 2
END OF wa_itab.Now the aim is that I would like to summarize this by Material. At the moment this will be showing me 100s of lines or more for a material dependant on requisitions. So in a single line I would like to see the material, total order quantity, etc etc.
How can I achieve this?
Thanks
Adeel
‎2009 Dec 26 8:09 AM
Create Another internal table
for example.
data : begin of it_summ ocurs 0,
matnr like marc-matnr,
qtyls LIKE eban-menge,
qty01 LIKE eban-menge,
qty02 LIKE eban-menge,
end of it_summ.
loop at wa_itab.
it_summ-matnr = wa_itab-matnr.
it_summ-qtyls = wa_itab-qtyls.
it_summ-qty01 = wa_itab-qty01.
it_summ-qty02 = wa_itab-qty02.
colect it_summ.
endloop.
you will get a single record for a material and sum of the quantity field u hav mentioned.
Try It.
‎2009 Dec 26 7:19 AM
Hi,
You can use AT NEW key word.
or take temp itab with only once char field MATNR and pass all data using MOVE-CORRESPONDING and append them to temp itab.
now use COLLECT key word.
for more info take F1 help on these key words.
Cheerz
Ram
‎2009 Dec 26 7:43 AM
hi,
Sort The internal table by MATNR.
If you want to get group by sum
then Use COLLECT key word.
if you want to fire begining of every line of a new MATNR.
then use AT NEW command.
‎2009 Dec 26 7:53 AM
hi,
can you please write a proper example using the table i have posted in the thread (Wa_itab) ? i have checked the keyword help and trying it but it doesn't seem to working.
thanks
Adeel
‎2009 Dec 26 8:12 AM
Hi,
As mentioned by others... For this you should know how to use Control break statements in a loop.
AT NEW... ENDAT.
AT END.... ENDAT.
AT LAST...ENDAT
AT FIRST..ENDAT
First try to read some help on the AT END, AT LAST.. and see how to use it.
Regards,
Sreekanth
‎2009 Dec 26 8:09 AM
Create Another internal table
for example.
data : begin of it_summ ocurs 0,
matnr like marc-matnr,
qtyls LIKE eban-menge,
qty01 LIKE eban-menge,
qty02 LIKE eban-menge,
end of it_summ.
loop at wa_itab.
it_summ-matnr = wa_itab-matnr.
it_summ-qtyls = wa_itab-qtyls.
it_summ-qty01 = wa_itab-qty01.
it_summ-qty02 = wa_itab-qty02.
colect it_summ.
endloop.
you will get a single record for a material and sum of the quantity field u hav mentioned.
Try It.
‎2009 Dec 26 8:21 AM
thanks Amit that solved that.
Just another question on this, lets say for example i in eban i have requisitions for 2009 and 2010 and i want to put the quantitys in seperate columns how would i do this using the same analagy? As you have mentioned i have done the loop and collect that will give me a single record for MATNR. Now how would I put the quantitys in the right column lets say i have 2 more columsn 2009 and 2010?
LOOP at wa_itab.
itab-matnr = wa_itab-matnr.
itab-werks = wa_itab-werks.
itab-menge = wa_itab-menge.
COLLECT itab.
ENDLOOP.
‎2009 Dec 26 8:24 AM
actually got that using if statements etc thanks again for ure help Amit.