Former Member

### Rounding in ABAP

How can i round off a value in ABAP Program and use it for further calculation

10|10000 characters needed characters exceeded

Former Member
Aug 22, 2007 at 10:10 AM

Goto Attributes of the program and tick the check box 'Fixed point Arithmetic' and it will do rounding off the numeric values.

10|10000 characters needed characters exceeded
• Aug 22, 2007 at 10:06 AM

Check the COMPUTE sentence help. There you will be pointed to proper "functions" to rounding/truncating numbers.

10|10000 characters needed characters exceeded
• Former Member
Aug 22, 2007 at 10:09 AM

hi,

DATA pack TYPE p VALUE '12345678'.

WRITE pack NO-GROUPING ROUND 2 DECIMALS 4.

Rewards points if it is useful

10|10000 characters needed characters exceeded
• Former Member
Aug 22, 2007 at 10:10 AM

Hi ,

You could make use of the following key words

<b>ceil</b> <i>Smallest integer number that is not smaller than the value of the argument arg.</i> <b>floor</b> <i>Largest integer number that is not larger than the value of the argument arg.</i>

Thanks..

Preetham S

10|10000 characters needed characters exceeded
• Aug 22, 2007 at 10:13 AM

Define a new variable type P with required decimals.. and assign the value to this new variable automatic rounding take places.

Ex: Data : amount type p decimals 2.

amount = '231233.548' .

Write amount. "AMOUNT will have 231233.55

amount = '3342322.573'.

Write amount. "AMOUNT will have 3342322.57

Regards,

SaiRam

10|10000 characters needed characters exceeded
• Former Member
Aug 22, 2007 at 10:14 AM

Option

... ROUND r

Effect

Scaled output of a field of type P.

The decimal point is first moved r places to the left ( r > 0) or to the right ( r < 0); this is the same as dividing with the appropriate exponent 10** r. The value determined in this way is output with the valid number of digits before and after the decimal point. If the decimal point is moved to the left, the number is rounded.

For further information about the interaction between the formatting options CURRENCY and DECIMALS, see the notes below.

Example

Effect of different ROUND specifications:

DATA: X TYPE P DECIMALS 2 VALUE '12493.97'.

WRITE: /X ROUND -2, "output: 1,249,397.00

/X ROUND 0, "output: 12,493.97

/X ROUND 2, "output: 124.94

/X ROUND 5, "output: 0.12

kiran.M

10|10000 characters needed characters exceeded
• Former Member
Aug 22, 2007 at 10:16 AM

Hi ,

try this:

data: v_p1 TYPE p LENGTH 4 DECIMALS 3 VALUE '5.234',

v_p2 TYPE C LENGTH 4 .

WRITE v_p1 to v_p2 DECIMALS 2.

write:/ v_p1,

v_p2.

10|10000 characters needed characters exceeded
• Former Member
Aug 22, 2007 at 10:25 AM

hi

try this shijith..........

DATA pack TYPE p VALUE '12345678'.

WRITE pack NO-GROUPING ROUND 3 DECIMALS 2.//here you can round up as you require......

REWARD IF USEFUL.....!!!!

10|10000 characters needed characters exceeded
• Former Member
Aug 22, 2007 at 10:44 AM

hi,

data : val type p decimals 3 .

data : sel type p decimals 0.

val = 1234.55.

sel = val.

write : sel.

10|10000 characters needed characters exceeded
• Former Member
Nov 26, 2015 at 11:50 AM

Hi,

just use packed data type with out decimals. it will automatic round off

Thanks

Lakshman