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 group records in itab

Former Member
0 Kudos
1,276

How can I sum up into one record the records in itab.

ex.

group amount

0001 50

0001 60

0003 10

0004 10

0004 20

should be:

group amount

0001 110

0003 10

0004 30

1 ACCEPTED SOLUTION

Former Member
0 Kudos
140

Hi Adrian,

Take another internal table <b>ITAB1</b> and use following code:

<b>LOOP AT ITAB INTO ITAB1.

COLLECT ITAB1.

ENDLOOP.</b>

Here at the end ITAB1 will be having your desired result.

This will definitely help you.

Regards,

Pragya

6 REPLIES 6

Former Member
0 Kudos
140

select group sum( amount ) into table itab

from dbtab GROUP by group.

Former Member
0 Kudos
140

Hai,

Instead of appending the records to the internal table, you can use the collect statement to meet your requirement.

0 Kudos
140

if records in internal table.


loop at itab.
  at new group.
    sum.
    itab header has summed record in here.
  endat.
endloop.

ibrahim

Former Member
0 Kudos
140

hi adrian,

u can use the <b>collect stmt</b>..

sort itab.

loop at itab.

at end of matnr.

<b>collect itab.</b>

endat.

0 Kudos
140

If there are four 0001 group in itab. I need to sum it up into one and remove the others. There should be only one record per group inside the itab.

Message was edited by: Adrian Jose Checa

Former Member
0 Kudos
141

Hi Adrian,

Take another internal table <b>ITAB1</b> and use following code:

<b>LOOP AT ITAB INTO ITAB1.

COLLECT ITAB1.

ENDLOOP.</b>

Here at the end ITAB1 will be having your desired result.

This will definitely help you.

Regards,

Pragya