‎2007 Jan 04 6:35 PM
Hello....
i have ainternal table with 4 fields....
material quantity field3 field4
auv123 100 xxxxx xxxx
auv123 200 xxxxx xxxx
auv111 100 xxxxx xxxx
auv123 400 xxxxx xxxx
auv111 200 xxxxx xxxx
auv222 100 xxxxx xxxx
i nedd a simple logic to get a o/p table like:
o/p result:
auv123 700 xxxxx xxxx
auv111 300 xxxxx xxxx
auv222 100 xxxxx xxxx
i.e I nedd to add QUANITY when MATERIAL number is same...and delete the extra rows...
<b>data types:</b>
material field is char
quantity fields is quan
other 2 fields( field 3 and field 4) in internal table are char and date type..
i need a simple logic for it...
it may sound bit silly for you ...
thanks....
‎2007 Jan 04 6:38 PM
‎2007 Jan 04 6:38 PM
‎2007 Jan 04 6:39 PM
Hi,
You can use collect statement and make sure you sort the internal table first.
SORT ITAB1.
LOOP AT ITAB1.
MOVE-CORRESPONDING ITAB1 TO ITAB2.
COLLECT ITAB2.
ENDLOOP.
Regards,
Ferry Lianto
‎2007 Jan 04 6:40 PM
Hi Aday,
Use <b>COLLECT</b> statement to meet your requirement.
COLLECT statement will sum up all numeric fields when all other non-numeric fields are same.
Thanks,
Vinay
‎2007 Jan 04 6:41 PM
In order to get a sum of the materials, you need to have another internal table with just Material and qty.
data: begin of isum,
matnr type mara-matnr,
qty type mseg-menge,
end of isum.
clear isum. refresh isum.
loop at itab.
isum-matnr = itab-matnr.
isum-qty = itab-qty.
collect isum.
endloop.Regards,
Rich Heilman
‎2007 Jan 04 6:51 PM
thanks for your quick responses...
here i have two other fields in the internal table...which are type DATE and CHAR..
im gettin problem when im using COLLECT statement..
im using R/3 620 release...
thanks..
‎2007 Jan 04 6:54 PM
then use SUM ie..
sort itab.
loop at itab.
at new matnr.
sum.
write: / itab-fld1,itab-fld2,itabfld3,itab-fld4.
endat.
endloop.
~Suresh
‎2007 Jan 04 6:59 PM
Right, you should try summing using another internal table, loop at the first and COLLECT into the second, the second internal table will only have material and qty, then when you want to know the total for material, you can simply read the ISUM internal table using the READ statement.
Regards,
Rich Heilman
‎2007 Jan 04 7:40 PM
thanks guys for all your quick replies....
i declared another table with only two fields...and used COLLECT statement...
then read the quantity and modified my original table after deleting adjacent duplicates..( as rich advised)...
once again thanks...
points will be awarded...