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.
Showing results for 
Search instead for 
Did you mean: 

dividing percentage between positions

Former Member
0 Kudos

Hello all,

I am adding different positions belonging to a document from the itab and calculating the percentage based on the percentage amount from another document.

I am using here at new docnr


then respective calculations.

The above is working fine with one document, but when there are more than one document with additional positions, it is not doing the calculations correctly.

is there any other way other than at new and sum? that we can use to sum itab columns.




Former Member
0 Kudos

You can try with On change of and sum

I thing your at new code is not triggerring as per your requirement.Try On change of

Active Contributor
0 Kudos

On change of is obsolete. Don't use it.

Former Member
0 Kudos

The below code will work same as At new functionality.

sample code: lv_mara1 type matnr,

                            lv_mara2 type matnr.

loop at it into wa.

lv_matnr1 = wa-matnr.

if lv_matnr1 <> lv_matnr2.

do what ever calculations u want to do.

lv_matnr2 = wa-matnr.



0 Kudos

Hi thanks for the code, I dont think I can achive what I want to with the given code. What exactly the situation is:

let say I have two documents 1000 and 2000.

Document 1000 has around 5 positions and the total amounts to 100 dollars.

Document 2000 has around 7 postions and the total amounts to 250 dollart.

For document 1000 there is a respective clearing posting doc lets say xyz with discount 20 dollars.

So with my code usting at new, I am first calculating the sum, I am getting 100 dollars, then I am fetching this discount amount from the respective clearing document, here its 20.

So 20 / 100 * 100 = 20%

Now this 20 % should get divided within the respective 5 positions.

All this I am able to do when there is one sigle document but when there are more document, calculations are not coming correctly.

Former Member
0 Kudos


I think you need to use at end of field. Check the link below it will help you and it has example also.

best regards,


Former Member
0 Kudos

Any suggestions?