Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Summing fields in an Internal table


I have an internal table in the following format:

Prod Order Material Req Qty Used Qty

A1 M1 2 2

A1 M2 1 0

A2 M3 3 3

A3 M1 4 0

I need to find out the material usage i.e. the no. of production orders the material was used in along with the sum of the required qty and used qty.

In the example above, the results will be

Material Req Qty Used Qty PO count

M1 6 2 2

M2 1 0 1

M3 3 3 1

I tried the following code:

SORT mat_comp_list_tmp BY matnr.

LOOP AT mat_comp_list_tmp INTO wa_comp_list_tmp.

  • Store the work area.

wa_comp_list_final = wa_comp_list_tmp.

AT END OF matnr.


  • Move the quantity.

wa_comp_list_final-req_qty = wa_comp_list_tmp-req_qty.

wa_comp_list_final-used_qty = wa_comp_list_tmp-used_qty.

wa_comp_list_final-cnt_aufnr = sy-dbcnt.

MODIFY mat_comp_list_tmp FROM wa_comp_list_final.



But this gives me a PO count per material per Prod. Order. This is not desired.

Is there any other way to acheive this. Any help will be greatly appreciated.



Former Member
Former Member replied

Hi .. I try this.

DATA: l_cont TYPE i,

itab TYPE mat_comp_list_tmp OCCURS 0 WITH HEADER LINE.

SORT mat_comp_list_tmp BY matnr.

LOOP AT mat_comp_list_tmp INTO wa_comp_list_tmp.

AT NET matnr.

CLEAR: l_cont, itab.


ADD 1 TO l_cont.

ADD wa_comp_list_tmp-req_qty TO itab-req_qty.

ADD wa_comp_list_tmp-used_qty TO itab-used_qty.

AT END OF matnr.

itab_cnt_aufnr = l_cont.

APPEND itab.



PD: itab must have matnr as first field

Thanks and Regards.

David Carballido

0 View this answer in context

Helpful Answer

Not what you were looking for? View more on this topic or Ask a question