05-21-2007 6:53 PM
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.
05-21-2007 6:58 PM
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
05-21-2007 7:59 PM
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
05-21-2007 8:09 PM
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.
05-21-2007 9:11 PM
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.
05-21-2007 9:34 PM
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.
05-21-2007 9:13 PM
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
05-21-2007 9:28 PM