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 ON FIELDS

Former Member
0 Likes
544

I have 4 charecter fields C1,C2,C3,C4 and 2 Numeric Fields N1 and N2. I need to sum N1 and N2 Numeric fields for unique C1 and C2 charecter fields. How can i do that? Kindly help me

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
523

try this

sort itab by c1 c2.

loop at itab.
 at end of C2.
  SUM.
 endat.
endloop.

4 REPLIES 4
Read only

Former Member
0 Likes
524

try this

sort itab by c1 c2.

loop at itab.
 at end of C2.
  SUM.
 endat.
endloop.

Read only

0 Likes
523

it is not working....

Read only

0 Likes
523

Sorry it works... I need to put the fields in sequnce C1, C2 in the structure. If i change the sequence like C1, C3, C2 in structure AT END OF C2 dosent works in the loop. Thanks for your help

Read only

ferry_lianto
Active Contributor
0 Likes
523

Hi,

Please try this something like this.


data: begin of itab2 occurs 0,
           c1c2(10),
           n1(10) type n,
           n2(10) type n.           
data: end of itab2.

sort itab by c1 c2 ascending.

loop at itab.
   itab2-c1c2(5) = itab-c1.
   itab2-c1c2+5(5) = itab-c2.
   itab2-n1 = itab-n1.
   itab2-n2 = itab-n2.
   collect itab2. 
endloop.

loop at itab2.
  write: / itab2-c1c2(5), itab2-c1c2+5(5), itab2-n1, itab2-n2. 
endloop.

Now your internal table ITAB2 has sum of field N1 and N2 of unique C1 and C2.

Regards,

Ferry Lianto