‎2007 Aug 26 12:55 PM
i have a itab in which having matnr and fkimg field as follwed
matnr fkimg
1005 100
1005 100
1005 80
1006 30
1006 20
1006 10.
now i want the sum of all fkimg of same matnr in a internal table .such as itab2 is having
matnr fkimg
1005 280
1006 60.
i tried at new matnr sum fkimg.but i don't know how to maintain sum values in int.table coz i don't need to display them at this point ,i need them later after doing some calculations .
can anybody help. i m stuck off in the middle of proogram it is urgent .points will be awarded surely .thanx
Message was edited by:
sarabjit kaur
Message was edited by:
sarabjit kaur
‎2007 Aug 26 3:57 PM
Hi Kaur,
Use COLLECT statement to achieve your requirement. As COLLECT will sum up all numeric fields in an internal table if all other non-numeric fields are same.
Declare another internal table and use COLLECT statement.
TYPES:
BEGIN OF TY_MATSUM,
MATNR TYPE MATNR,
FKIMG TYPE FKIMG,
END OF TY_MATSUM.
DATA IT_MATSUM TYPE STANDARD TABLE OF TY_MATSUM WITH HEADER LINE.
LOOP AT ITAB.
COLLECT ITAB INTO IT_MATSUM.
ENDLOOP.
LOOP AT IT_MATSUM.
WRITE:/ IT_MATSUM-MATNR , IT_MATSUM-FKIMG.
ENDLOOP.
Thanks,
Vinay
‎2007 Aug 26 2:19 PM
Hi Sarabjit,
Let say following table in internal table --> itab1
matnr fkimg
1005 100
1005 100
1005 80
1006 30
1006 20
1006 10.
and itab2 -->
matnr fkimg
1005 280
1006 60.
DATA : v_fking TYPE (same as fking).
CLEAR v_fking.
LOOP AT int_tab1 INTO wa_tab1.
v_fking = v_fking + wa_tab1-fking.
AT NEW matnr.
MOVE v_fking TO wa_tab1-fking.
APPEND wa_tab1 TO tab_final.
clear : v_fking , wa_tab1.
ENDAT.
ENDLOOP.
‎2007 Aug 26 2:52 PM
Hi,
My advise would be, please sort the internal table before u use the following logic.
I thnk following will be better.
sort itab1 by matnr fkimg.
Read table itab1 into ls_itab1_temp index 1.
loop at itab1 into ls_itab.
l_fking = l_fking + ls_tab1-fking.
if ls_itab1_temp-matnr ne ls_itab1.
MOVE l_fking TO ls_tab1-fking.
APPEND ls_tab1 TO itab_final.
ls_itab1_temp = ls_itab.
clear : l_fking , ls_tab1.
endif.
endloop.
Regards,
Niyaz
‎2007 Aug 26 3:57 PM
Hi Kaur,
Use COLLECT statement to achieve your requirement. As COLLECT will sum up all numeric fields in an internal table if all other non-numeric fields are same.
Declare another internal table and use COLLECT statement.
TYPES:
BEGIN OF TY_MATSUM,
MATNR TYPE MATNR,
FKIMG TYPE FKIMG,
END OF TY_MATSUM.
DATA IT_MATSUM TYPE STANDARD TABLE OF TY_MATSUM WITH HEADER LINE.
LOOP AT ITAB.
COLLECT ITAB INTO IT_MATSUM.
ENDLOOP.
LOOP AT IT_MATSUM.
WRITE:/ IT_MATSUM-MATNR , IT_MATSUM-FKIMG.
ENDLOOP.
Thanks,
Vinay