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 of fields validation

Former Member
0 Kudos

I have a table where in i have 3 fields

a, b, and C(percentage)

My requirement is to calculate the sum of field C, for A and B combination.

Group by A and B. and the total sum of C for this combination should be 100%Please send me some code if you have any idea about this logic.

Thanks in advance.

7 REPLIES 7

Former Member
0 Kudos

Hi,

Try this..



TYPES: BEGIN OF TYPE_DATA,
               SUM TYPE NETWR,
               A      TYPE ZTABLE-A,
               B      TYPE ZTABLE-B,
             END OF TYPE_DATA.

DATA: T_DATA TYPE STANDARD TABLE OF TYPE_DATA.

* Get the data from the table.
SELECT SUM( C ) A B
             INTO TABLE T_DATA
             FROM ZTABLE
             GROUP BY a b.

Thanks

Naren

0 Kudos

Thanks for your solution.

I forgot to mention that i need to do validations before i upload into ztable.

A,B, C are three fields in my internal table ( that i uploaded from excel)

I need to do the sum validation before i upload to ztable.

Any suggestions regarding this

0 Kudos

sort intab by a b.

loop at intab.

sum_c = sum_c + c.

at end of b.

if sum_c ne 100.

message -- error message.

endif.

clear sum_c.

endat.

0 Kudos

Hi Sujamol Augustine

The solution suggested by you doesnt help much. Thanks for your input.

A B C

na 12 30

na 13 30

an 13 40

na 12 70

an 13 50

Here sum should be

A B C

na 12 100

an 13 90

na 13 30

Plz give me some suggestions.

0 Kudos

what do you mean by solution dont help.. ?

sort intab by a b.

loop at intab.

sum_c = sum_c + c.

<b>at end of b.

newtab-a = intab-a.

newtab-b = intab-b.

newtab-sum = sum_c.

append newtab.</b>clear sum_c.

endat.

endloop.

Former Member
0 Kudos

Hi,

You can use collect statement to sum up the values in the field c based on a and b.

Declare an internal table with those three fields..

Ex..



LOOP AT itab.

* Collect.
  COLLECT IT_COLLECT.

ENDLOOP.

Thanks,

Naren

0 Kudos

Collect doesnt work out as my field is a decimal.