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: 

calculation incorrect in MV45AFZZ in sales order

former_member496861
Participant
0 Kudos

Hi All,

For some reason, calculation in MV45AFZZ in form Userexit_save_document_prepare is not working for field zgp_perc.

I have the code:

data:zgp_amt like tkomp-netwr,

zgp_perc like tkomp-netwr.

loop at tkomp.

zgp_amt = tkomp-netwr - tkomp-wavwr.

zgp_perc = gp_amt / tkomp-netwr.

1187.03 - = 340.00 - 1527.03.

zgp_perc = 0.03 - (should be 3.49)

Second loop: 62.17 = 97.50 - 35.33

zgp_perc = 0.01 (it should be 0.63)

Endloop.

I wonder why the gp_perc is not calculating correctly ?

thanks

Joyce

1 ACCEPTED SOLUTION

former_member589029
Active Contributor
0 Kudos

Your percentage field is defined as NETWR hence your numbers are off by two decimals:

0.03 instead of 3.49 (if you would have more decimals you would see 0.0349)

0.01 instead of 0.63 (if you would have more decimals you would see 0.0063 and that rounded to two decimals is going to be 0.01)

You could do:

zgp_perc = gp_amt * 100 / tkomp-netwr.

Hope that helps,

Michael

2 REPLIES 2

former_member589029
Active Contributor
0 Kudos

Your percentage field is defined as NETWR hence your numbers are off by two decimals:

0.03 instead of 3.49 (if you would have more decimals you would see 0.0349)

0.01 instead of 0.63 (if you would have more decimals you would see 0.0063 and that rounded to two decimals is going to be 0.01)

You could do:

zgp_perc = gp_amt * 100 / tkomp-netwr.

Hope that helps,

Michael

0 Kudos

Hi Michael,

It worked ! I will try a field with more decimals.

Appreciate your quick reply.

Thank you !

Joyce