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

sum in itab

Former Member
0 Likes
737

Hello,

In my itab there are 5 fields. In my 1st colmn there are 4 diff data for that other colmn contains diff respective data.

I sorted itab my colmn1.

Then it will give itab like

x s d f

x f q e

y p o u

y l k h

z m h g

So, what i want is to sum other colmn for x, sum for y , sum for z . for that i tried ' at new' 'sum'

but id did not work. can u tell me plz.?

Thanks.

Hello,

In my itab there are 5 fields. In my 1st colmn there are 4 diff data for that other colmn contains diff respective data.

I sorted itab my colmn1.

Then it will give itab like

x s d f

x f q e

y p o u

y l k h

z m h g

So, what i want is to sum other colmn for x, sum for y , sum for z . for that i tried ' at new' 'sum'

but id did not work. can u tell me plz.?

Thanks.

6 REPLIES 6
Read only

Former Member
0 Likes
710

Hi Rani,

Lets say ur first column name is col1.

try this:


loop at itab.
at end of col1.
sum.
move itab to itab2.
append itab2.
end at.
endloop.

itab2 will have all your summed entries according to your column 1.

careful while declaring itab1 and itab2, col1 should be your first field.

hope this give you some idea.

ags.

Read only

Former Member
0 Likes
710

Hi, Rani.

Try using an auxiliar internal table, and COLLECT statement.

Like this:


  SORT itab BY field1.
  LOOP AT tg_itab INTO wa_itab.
    COLLECT wa_itab INTO tg_itab_aux.
  ENDLOOP.

First, field1 needs to be a key field.

Then, itab must be sorted by field1

If it works or not, just let me know,

Brian Gonsales.

Read only

0 Likes
710

hello,

Thanks for reply.

But collect is not working.

Read only

0 Likes
710

it should work, there must be something in the collect or the key.

Show how are you declaring your table and how are you using the collect

Read only

0 Likes
710

Collect and sum will work for numbers and integers.

Check F1 help on COLLECT or SUM.

This is common tag and we have used it many times to do sum.

other way is to loop on table and then code for sum.


itab1[] = itab2[]

sort itab1 by col1.
delete adjacent duplicates from itab1 comparing col1.

loop at itab1.
loop at itab2 where col1 = itab1-col1

....do sum here
itab3-val1 = itab3-val1 + itab2-value.
..
...

endloop.
append itab3.
endloop.

itab3 will have all summed up value.

This is long approach so i prefer SUM or COLLECT.

hope this helps.

Thanks,

Ags..

Edited by: Agasti Kale on Jun 3, 2008 9:33 PM

Read only

0 Likes
710

data type is 'curr'.

I can to delete adj. dupl. as it will delete all row. because other colm has diff data .

thanks