Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

at new statement

Former Member
0 Likes
520

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
499

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

3 REPLIES 3
Read only

Former Member
0 Likes
499

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.

Read only

0 Likes
499

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

Read only

Former Member
0 Likes
500

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