12-03-2007 8:34 AM
Hey All...
Plz check the following piece of code.
parameters: sec type i.
data: min type i,
bals type i.
min = sec / 60.
bals = sec mod 60.
if bals > 30.
min = min + 1.
endif.
write:/ 'Second(s)', sec, '=', min, 'Minute(s)'.
Give the input as 515 and chk out the result.
We expect the result to be 9.
But system shows answer as 10.
Plz chk.!
12-03-2007 8:37 AM
coz SAP rounds off 8.58 to 9
<b>min = sec / 60.</b>
gives min = 9
so mins becomes 9..
then you add 1 to it...
<b>bals = sec mod 60.</b>
gives bals = 35
<b>if bals > 30.
min = min + 1.</b>
this makes mins = 10
12-03-2007 8:39 AM
12-03-2007 8:40 AM
Hi,
This is normal, as MIN is equal to '9' because it's rounded, in reality it should be '8.46'.
You must use something like this :
min = TRUNC( sec / 60 ).
<b>This is the right piece of code :</b>
parameters: sec type i.
data: min type i,
bals type i,
x type p decimals 3.
x = sec / 60.
min = trunc( x ) .
bals = sec mod 60.
if bals > 30.
min = min + 1.
endif.
write:/ 'Second(s)', sec, '=', min, 'Minute(s)'.
Hope this helps,
Erwan
12-03-2007 8:47 AM