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: 

summation

Former Member
0 Kudos

hi experts,

i got the values in internal table.

key activ hsl csale

01 koae 786.88 800.00

01 rmwl 567.77 987.55

01 koae 100.55 800.00

01 sd00 432.55 234.66

02 koae 650.00 400.00

02 rmwl 156.44 412.88

02 koae 700.00 500.00

02 sd00 100.77 500.88

i want summation of hsl and csale where same key and same activ and i need to put in another jtab internal table.

that means jtab values nust be like this.

key activ hsl csale

01 koae 886.88 1600.00

02 koae 1350.00 900.00

for this how can i write the code can anybody help me.

answer will be rewarded.

venkat.

6 REPLIES 6

Former Member
0 Kudos

Hi,

If key is a character field, collect itab will work.

Just put collect itab instead of append itab and check the output.

regards,

senthil

0 Kudos

Hi

Check this code,

data : begin of itab occurs 0,

key(2),

activ(4),

hsl type p decimals 2,

csale type p decimals 2,

end of itab.

itab-key = '01'.

itab-activ = 'koae'.

itab-hsl = '786.88'.

itab-csale = '800.00'.

collect itab.

itab-key = '01'.

itab-activ = 'rmw1'.

itab-hsl = '567.77'.

itab-csale = '987.55'.

collect itab.

itab-key = '01'.

itab-activ = 'koae'.

itab-hsl = '100.55'.

itab-csale = '800.00'.

collect itab.

  • add all your values like this and check

  • itab-key = '01'.

  • itab-activ = 'koae'.

  • itab-hsl = '786.88'.

  • itab-csale = '800.00'.

  • collect itab.

loop at itab.

write 😕 itab-key, itab-activ, itab-hsl, itab-csale.

endloop.

Regards,

Senthil

suresh_datti
Active Contributor
0 Kudos

You can use COLLECT.

~Suresh

Former Member
0 Kudos

sort itab.

loop at itab

at end of activ.

sum.

move-correspoding itab to itab1.

append itab1.

endat.

endloop.

Former Member
0 Kudos

Hi,

First sort the internal table depending upon the fields and then using AT NEW u can find the sum.

sort itab by key activ.

loop at itab.

w_hsl = w_hsl + hsl.

w_cscale = w_cscale + cscale

at new activ.

  • here append the data into another table

endat.

endloop.

Regards,

Vibha

  • Reward points if it helps

Former Member
0 Kudos

hi,

try this,

sort ftab by key activ.

loop at ftab.

clear: m, n.

at new active.

m = ftab-activ.

loop at ftab where active = m.

n = n + 1.

endloop.

if n > 1.

move ftab-... to btab-.....

move ftab-... to btab-.....

move ftab-... to btab-.....

collect btab.

endif.

endat.

endloop.