Application Development 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: 

Sum a particular filed based on other field in the Internal table?

Former Member
0 Kudos
822

Hi Guys,

I am having an Internal table with G/L account number and Amount in Local Currency .so in this we will have some g/l account number's repeated with different amount.I need to add all the Amounts in the amount column with same G/L account number and make it into a single entry.so how to do this ?

Thanks,

Gopi.

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos
276

COLLECT will do it easily.

DO like this:

LOOP AT ITAB. 
IT_SUM-GL_ACC = ITAB-GL_ACC.
IT_SUM-AMOUNT = ITAB-AMOUNT.
COLLECT IT_SUM.
CLEAR IT_SUM.
ENDLOOP.

Regards,

Naimesh Patel

3 REPLIES 3

naimesh_patel
Active Contributor
0 Kudos
277

COLLECT will do it easily.

DO like this:

LOOP AT ITAB. 
IT_SUM-GL_ACC = ITAB-GL_ACC.
IT_SUM-AMOUNT = ITAB-AMOUNT.
COLLECT IT_SUM.
CLEAR IT_SUM.
ENDLOOP.

Regards,

Naimesh Patel

Former Member
0 Kudos
276

Hi Gopi,

declare another wa1 same as wa.

declare final_tab same as itab.

clear wa1.

sort itab by accno.

loop at itab into wa.

if wa-accno = wa1-accno.

wa-amt = wa-amt + wa1-amt.

modify final_tab from wa transporting amt.

else.

append wa to final_tab.

endif.

wa1 = wa

endloop.

Reward if it helps,

Satish

0 Kudos
276

Hi,

I need to do it in same way. Please Help.