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: 

Erreneous Output

Former Member
0 Kudos

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.!

4 REPLIES 4

Former Member
0 Kudos

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

0 Kudos

K.. but I need the correct answer!

Former Member
0 Kudos

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

Former Member
0 Kudos

Thx