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

How to calculate upper limit of variable ?

Hello Friends,

I want small logic here,

I have one variable like amt = 5.001.

If amount increses up to 5.005 then amt should be 5.000

i have created constant c_val = 0.005 also

if amount increses like 5.006 then amount should be 6.000

for example,

5.000 should be 5.000

5.001 should be 5.000

5.002 should be 5.000

5.003 should be 5.000

5.004 should be 5.000

5.005 should be 5.000

5.006 should be 6.000

5.007 should be 6.000

5.008 should be 6.000

5.009 should be 6.000

Note : i dont want to use CEIL fn.

points rewarded soon

Regards,

RH

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 25, 2008 at 10:59 AM

    Hi,

    Please refer the below program..

    Reward points if it is useful...

    data: v_amt type p decimals 3 value '5.006',

    v_frc type p decimals 3 .

    CONSTANTS: c_val TYPE p DECIMALS 3 value '0.005'.

    v_frc = frac( v_amt ).

    if v_frc <= c_val.

    v_amt = floor( v_amt ).

    else.

    v_amt = ceil( v_amt ).

    endif.

    write:/ v_amt.

    Regards,

    vijay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 25, 2008 at 10:20 AM

    hi,

    Use ROUND FM ..

    Regards,

    Santosh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 25, 2008 at 10:23 AM

    Hi

    Use either ROUND or FLOOR to do so

    DATA n TYPE p DECIMALS 2.

    DATA m TYPE p DECIMALS 2 VALUE '-5.55'.

    n = abs( m ). WRITE: 'ABS: ', n.

    n = sign( m ). WRITE: / 'SIGN: ', n.

    n = ceil( m ). WRITE: / 'CEIL: ', n.

    n = floor( m ). WRITE: / 'FLOOR:', n.

    n = trunc( m ). WRITE: / 'TRUNC:', n.

    n = frac( m ). WRITE: / 'FRAC: ', n.

    The output appears as follows:

    ABS: 5.55

    SIGN: 1.00-

    CEIL: 5.00-

    FLOOR: 6.00-

    TRUNC: 5.00-

    FRAC: 0.55-

    regads

    Shiva

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      well the best way is to use CEIL and FLOOR commands.

      
      IF variable LE 5.0005.
      
      variable = FLOOR(variable).
      
      ENDIF.
      
      IF variable GT 5.0005 AND variable LT 6.000.
      
      variable = CEIL(variable).
      
      ENDIF.
      
      

      Reward if helpful.

      Regards.

  • author's profile photo Former Member
    Former Member
    Posted on Mar 25, 2008 at 10:29 AM

    Hi Ronny,

    1. using integer concept and the c_val as you said,

    we can use this kind of logic.

    2. Just copy paste.

    3. Note : N2 is the final output variable.

    REPORT ABC.

    DATA : NUMBER TYPE P DECIMALS 3.

    DATA : C_VAL TYPE P DECIMALS 3.

    DATA : INTEGER TYPE I.

    DATA : N1 TYPE P DECIMALS 3.

    DATA : N2 TYPE P DECIMALS 3.

    *----


    C_VAL = '0.005'.

    NUMBER = '5.005'.

    *----


    INTEGER = NUMBER.

    N1 = NUMBER - C_VAL.

    IF N1 > INTEGER.

    N2 = INTEGER + 1.

    ELSE.

    N2 = N1.

    ENDIF.

    WRITE :/ NUMBER.

    WRITE :/ INTEGER.

    WRITE :/ N1.

    WRITE :/ N2.

    regards,

    amit m.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 25, 2008 at 10:39 AM

    Hi,

    Try using FM ROUND.

    Thanks,

    Sriram Ponna.

    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.