rounding problem

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
RGoeken
Posts: 45
Joined: Fri Aug 11, 2006 3:18 am

rounding problem

Post by RGoeken » Tue Aug 30, 2011 1:58 am

Hi,

I have a rounding problem on a quantity field. Here's the code:

COMPUTE lv_quantity = ls_vbap-kwmeng / ls_packpo_r-trgqty * ls_packpo_p-trgqty.

All fields are defined as quantity fields with a length of 15 with three decimals.
The value off the fields is: 204 / 40 * 1 which should have an outcome of 5.100 right?
But it gives me a value of 5.000 (rounded) ?????
I also tried it with lv_quantity as type P and without the compute statement but all with the same result.
Any ideas? Thanks!

SHS
Posts: 483
Joined: Mon Mar 06, 2006 3:57 am

Re: rounding problem

Post by SHS » Tue Aug 30, 2011 3:59 am

Is your lv_quantity defined as type P as well?
And is the fixed point arithmetic setting switched on (in program attributes?)

RGoeken
Posts: 45
Joined: Fri Aug 11, 2006 3:18 am

Re: rounding problem

Post by RGoeken » Tue Aug 30, 2011 4:23 am

I have tried it with lv_quantity as a quan field and also as P but both didn't work.
The code is in a user exit in program mv45afzz ( SAPMV45A) .
The fixed point arithmetic setting is not switched on in SAPMV45A.
Could that be the problem? I don't want to change the program attributes without
exactly knowing the consequences. Thanks, for your answer.

SHS
Posts: 483
Joined: Mon Mar 06, 2006 3:57 am

Re: rounding problem

Post by SHS » Tue Aug 30, 2011 5:34 am

I think that's the problem.
You should not change the settings for the SAPMV45A-program.
Instead, make a function module that calculates the value for you. In the main program of your function module you can set the switch to ON.
Or, change the type of lv_quantity to F but be aware that using this type can have unwanted side-effects (but you should check the help for that...)

RGoeken
Posts: 45
Joined: Fri Aug 11, 2006 3:18 am

Re: rounding problem

Post by RGoeken » Tue Aug 30, 2011 9:14 am

Thanks! Type F solved the problem and I don't seen any nasty side effects.

Post Reply