09-10-2008 12:51 AM
Hello,
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.
For E.g.:
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.
Thanks,
Rugmani
09-10-2008 7:03 PM
Hi,
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.
ENDLOOP.
COLLECT compares all the character fields and sums the numeric and amount fields if the character fields are same.
See if it works...
- Hemant
09-10-2008 1:51 AM
Hi,
have you tried to use COLLECT. Check COLLECT in ABAP documentation.
Cheers
09-10-2008 2:21 AM
Hi,
Before you should sort the field.
sort <field>
then
at end of <filed>
sum
endat.
09-10-2008 6:17 PM
Hello,
I tried using the AT END OF...ENDAT but it doesnt work.
My code is like this:
SORT mat_comp_list BY aufnr matnr.
LOOP AT mat_comp_list INTO wa_comp_list.
AT END OF aufnr.
AT END OF matnr.
SUM.
MODIFY mat_comp_list FROM wa_comp_list.
ENDAT.
ENDAT.
ENDLOOP.
Please let me know if this is correct.
Thanks,
Rugmani
09-10-2008 6:34 PM
Hi,
Try this..
SORT mat_comp_list BY aufnr matnr.
DATA: wa_comp_list_tmp LIKE wa_comp_list.
LOOP AT mat_comp_list INTO wa_comp_list.
* Store the work area.
wa_comp_list_tmp = wa_comp_list.
AT END OF matnr.
SUM.
* Move the quantity.
wa_comp_list_tmp-required_qty = wa_comp_list-required_qty.
wa_comp_list_tmp-used_qty = wa_comp_list-used_qty.
MODIFY mat_comp_list FROM wa_comp_list_tmp.
ENDAT.
ENDLOOP
.
Thanks
Naren
09-10-2008 7:03 PM
Hi,
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.
ENDLOOP.
COLLECT compares all the character fields and sums the numeric and amount fields if the character fields are same.
See if it works...
- Hemant
09-10-2008 8:53 PM
09-10-2008 7:40 PM
Hi,
Check the following code:
DATA: BEGIN OF LINE,
COL1 TYPE C,
COL2 TYPE I,
COL3 TYPE I,
END OF LINE.
DATA ITAB LIKE HASHED TABLE OF LINE
WITH UNIQUE KEY COL1 COL2.
LINE-COL1 = 'A'.
DO 3 TIMES.
LINE-COL2 = SY-INDEX.
LINE-COL3 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
LINE-COL1 = 'B'.
DO 3 TIMES.
LINE-COL2 = 2 * SY-INDEX.
LINE-COL3 = ( 2 * SY-INDEX ) ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
SORT ITAB.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
AT END OF COL1.
SUM.
ULINE.
WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
SKIP.
ENDAT.
AT LAST.
SUM.
ULINE.
WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
ENDAT.
ENDLOOP.
Regards,
Bhaskar