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

ask abap logic

Former Member
0 Likes
600

Hi All,

I need to get the percentage of the amount allocated from 1 company to other company.

i put the data in internal table

pco rco amt percentage

A X 20k

A X 15k

A X 5k

i need to do collect so that same record can summate up

[internal table 2]

pco rco amt pct

A X 40k 27.97%

A Y 75k

A Z 28k

B S 68k

B F 47k

example above, co A has allocated its charges to co X,Y and Z where the total charges are 40k, 75k and 28k respectively. for co X, the percentage is (40/143)*100%. the same formula applies to other company.

May i know what method should be efficient to get the percentage that charge to each rco? Should i create another internal table called [total amount] with pco and total amt. when loop the [internal table 2] above i can read table of the [total amount] to get the total amount for each pco.

need advice.

thanks alot.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
566

now ur internal table has

A X 20

A X 40

A X 5

A Y 40

A Z 40

A Z 30

B P 40

B Z 70

loop at itab.

collect itab.

endloop.

So itab will have

A X 65

A Y 40

A Z 70

B P 40

B Z 40

Now, take one more internal table itab2 which has

A 65

A 40

A 70

B 40

B 40

loop at itab1.

collect itab1.

endloop.

itab1 will have

A 175

B 80

loop at itab.

v_tabix = sy-tabix.

read table itab1 with key <field1> = itab-<field1>.

if sy-subrc = 0.

itab-field4 = (itab-field3/itab1-field2)* 100.

modify itab index v_tabix.

endif.

endloop.

Message was edited by:

Ramesh Babu Chirumamilla

Hi All,

I need to get the percentage of the amount allocated from 1 company to other company.

i put the data in internal table

pco rco amt percentage

A X 20k

A X 15k

A X 5k

i need to do collect so that same record can summate up

[internal table 2]

pco rco amt pct

A X 40k 27.97%

A Y 75k

A Z 28k

B S 68k

B F 47k

example above, co A has allocated its charges to co X,Y and Z where the total charges are 40k, 75k and 28k respectively. for co X, the percentage is (40/143)*100%. the same formula applies to other company.

May i know what method should be efficient to get the percentage that charge to each rco? Should i create another internal table called [total amount] with pco and total amt. when loop the [internal table 2] above i can read table of the [total amount] to get the total amount for each pco.

need advice.

thanks alot.

3 REPLIES 3
Read only

Former Member
0 Likes
567

now ur internal table has

A X 20

A X 40

A X 5

A Y 40

A Z 40

A Z 30

B P 40

B Z 70

loop at itab.

collect itab.

endloop.

So itab will have

A X 65

A Y 40

A Z 70

B P 40

B Z 40

Now, take one more internal table itab2 which has

A 65

A 40

A 70

B 40

B 40

loop at itab1.

collect itab1.

endloop.

itab1 will have

A 175

B 80

loop at itab.

v_tabix = sy-tabix.

read table itab1 with key <field1> = itab-<field1>.

if sy-subrc = 0.

itab-field4 = (itab-field3/itab1-field2)* 100.

modify itab index v_tabix.

endif.

endloop.

Message was edited by:

Ramesh Babu Chirumamilla

Read only

andreas_mann3
Active Contributor
0 Likes
566

hi,

yes make a new table ptab:

pco sum

A 143

B 115

..

so you can calculate when you loop your itab.

readt table ptab with key pco = itab-pco.

itab-percent = itab-amt / ptab-sum * 100.

Andreas

Message was edited by:

Andreas Mann

Read only

Former Member
0 Likes
566

hi all,

thanks for the help. i will try out.

rgds