Skip to Content
author's profile photo Former Member
Former Member

Erreneous Output

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 08: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 08: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 08:47 AM

    Thx

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.