Compare 2 rows of an internal table
I have a requirement where I have to compare the rows of an internal table (table containing poduction order no., material no, required quantity and used quantity) and get a count of the required quantity and used quantity for the same materials belonging to one production order.
Prod Ord Material Req. Qty Used Qty
123 A 1 1
133 A 2 0
123 B 1 1
123 A 3 3
The quantities of Rows 1 and 4 need to be summed up. (as they correspond to the same material used within the same production order).
Please let me know if there is a method to do this.
I tried using SUM within AT END OF...ENDAT, but it does not do the summation, maybe because these quantity fields have the data type as QUAN.
Helpful suggestions will be greatly appreciated.
Hemant Satpute replied
Try using this:
1. Use the COLLECT command when u populate the internal table. Use it instead of Append.
ex: COLLECT WA_COMP TO IT_COMP.
2. Create another itab: IT_COMP2.
LOOP AT IT_COMP INTO WA_COMP.
COLLECT WA_COMP TO IT_COMP2.
COLLECT compares all the character fields and sums the numeric and amount fields if the character fields are same.
See if it works...