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

help in SUM

Former Member
0 Likes
739

Hi,

i Have table like below and i wont to sum the last Colman (c_hr)

to 1 field cnt What is the Best Way to do That?

Regards

Data cnt type P DECIMALS 2.

*Date               a_hr      b_hr    c_hr* 
*20040101	 9.00	   9.00	   1.00*
*20040105	 5.00	   9.00	   0.56*
*20040108	 3.00	   9.00	   0.33*
*20040112	 9.00	   9.00	   1.00*
*20040115	 9.00	   9.00	   1.00*

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
719

hi Ricardo,

one way is:

LOOP AT itab.

cnt = cnt + itab-c_hr.

ENDLOOP.

hope this helps

ec

6 REPLIES 6
Read only

Former Member
0 Likes
719

better do a loop and add the field in to the required variable

Read only

JozsefSzikszai
Active Contributor
0 Likes
720

hi Ricardo,

one way is:

LOOP AT itab.

cnt = cnt + itab-c_hr.

ENDLOOP.

hope this helps

ec

Read only

Former Member
0 Likes
719

Hi,

Try this.

Loop at <int.table> into <work area>.

cnt = cnt + <work area>-c_hr.

clear <work area>.

endloop.

After this, you will have the sum in one variable cnt.

Read only

Former Member
0 Likes
719

an option is:

data: count like i_t-c_hr.

clear count.

loop at i_t.

count = count + c_hr.

endloop.

or u can use the command COLLECT check with sap help..

Read only

Former Member
0 Likes
719

Hello,


CLEAR cnt
LOOP AT itab INTO line.
  cnt = line-c_hr + cnt.
ENDLOOP.

Regards,

Read only

former_member182354
Contributor
0 Likes
719

Hi,

Use collect statement....

Lop at itab.

.......

collect itab.

endloop.

Raghav