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 field in table

Former Member
0 Kudos

hallow

i have table with emp miss for month and i wont to add another line with sum of miss days for month how i can do that ?

kostl month1 month2 month3 month4 month5 month6

1000-10 532 456 503 453 522 500

1000-11 23 20 21 19 22 20

for this table ccmissdays i wont to add line with bold (sum)

kostl month1 month2 month3 month4 month5 month6

1000-10 532 456 503 453 522 500

1000-11 23 20 21 19 22 20

<b>555 476 524 472 544 520</b>

Best regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos

LOOP at itab into wa_itab.

at last.

sum.

lz_month1 = wa_itab-month1.

lz_month2 = wa_itab-month2.

.

.

.

endat.

write : / here display your records lz_month1 and lz_month2 will be having the sum.

endloop.

12 REPLIES 12

Former Member
0 Kudos

Try this one, after this, you should have a sum of all the values in your internal table inside the table.


loop at table.
  at last.
    sum .
    append table.
  endat.
endloop.

But why would you do this if you can just write or assign the total values of each field inside the code

at last...endat.

Former Member
0 Kudos

LOOP at itab into wa_itab.

at last.

sum.

lz_month1 = wa_itab-month1.

lz_month2 = wa_itab-month2.

.

.

.

endat.

write : / here display your records lz_month1 and lz_month2 will be having the sum.

endloop.

0 Kudos

loop at iatb.

at last.

sum .

itab-month1 = itab-month1.

itab-month2 = itab-month2.

itab-month3 = itab-month3.

itab-month4 = itab-month4.

itab-month5 = itab-month5.

itab-month6 = itab-month6.

append itab..

endat.

endloop.

Regards

vasu

0 Kudos

hi mukesh

assume i have more than 2 lines (maybe 10) it work also?

Regards

0 Kudos

Hi TAL,

Yes it will work for any number of lines.

SUM command calculates SUM for all the records of Internal table but it should be Numeric.

Regards,

Mukesh Kumar

0 Kudos

hi vasu

assume i have more than 2 lines (maybe 10) it work also?

Regards

0 Kudos

Hi TAL....

ya it will work....

as we r giving at last....and SUM adds up everything....

Regards

Vasu

0 Kudos

hi vasu

i try your saggstion and its work partly ,i have sum but the loop never stop and i have dump, i wont just to to sum for the lines i have in table this is part of what i get


1000-101	532	456	503
1000-111	23	20	21
**********	555	476	524
**********	1110	952	1048
**********	2220	1904	2096

i dont wont 4 and five line

Best regards

0 Kudos

hi mukesh

i try your saggstion and its work partly ,i have sum but the loop never stop and i have dump, i wont just to to sum for the lines i have in table this is part of what i get

1000-101 532 456 503

1000-111 23 20 21

********** 555 476 524

********** 1110 952 1048

********** 2220 1904 2096

i dont wont 4 and five line

Best regards

0 Kudos

loop at itab.

at last.

sum.

itab-month2 = itab-month2.

itab-month3 = itab-month3.

itab-month4 = itab-month4.

itab-month5 = itab-month5.

itab-month6 = itab-month6.

<b>clear itab-month1.

append itab.

clear itab.

exit.</b>

endat.

endloop.

Give EXIT. after appending.....

Regards

Vasu

Former Member
0 Kudos

Hi,

t_month1 = t_month2 =t_month3 = t_month4 = t_month5 =t_month6 =0.

loop at itab

t_month1 = t_month1+itab-month1.

t_month2 = t_month2+itab-month2.

t_month3 = t_month3+itab-month3.

t_month4 = t_month4+itab-month4.

t_month5 = t_month5+itab-month5.

t_month6 = t_month6+itab-month6.

l_index = sy-tabix.

endloop.

clear itab.

l_index = l_index + 1.

itab-mnth1 = t_month1.

itab-mnth2 = t_month2.

itab-mnth3 = t_month3.

itab-mnth4 = t_month4.

itab-mnth5 = t_month5.

itab-mnth6 = t_month6.

insert itab index l_index.

    • reward if solved problem**

former_member188827
Active Contributor
0 Kudos

loop at itab.

zmonth1_sum = itab-month1 + zmonth1_sum.

zmonth2_sum = itab-month2 + zmonth2_sum.

zmonth3_sum = itab-month3 + zmonth3_sum.

zmonth4_sum = itab-month4 + zmonth4_sum.

zmonth5_sum = itab-month5+zmonth5_sum.

zmonth6_sum = itab-month6 + zmonth6_sum.

endloop.

itab-kostl = ' '.

itab-month1 = zmonth1.

itab-month2 = zmonth2.

itab-month3 = zmonth3.

itab-month4 = zmonth4.

itab-month5 = zmonth5.

itab-month6 = zmonth6.

append itab.