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: 

How to calculate upper limit of variable ?

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

8 REPLIES 8

Former Member
0 Kudos

hi,

Use ROUND FM ..

Regards,

Santosh

Former Member
0 Kudos

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

0 Kudos

I dont want to use ROUND or CEIL.

and waht will be the condition ???

Edited by: Ronny Hanks on Mar 25, 2008 11:27 AM

0 Kudos

Then

you can try FLOOOR

regards

Shiva

0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hi,

Try using FM ROUND.

Thanks,

Sriram Ponna.

Former Member
0 Kudos

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