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: 

Rounding in ABAP

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

former_member434229
Active Participant
0 Kudos

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

10 REPLIES 10

VXLozano
Active Contributor
0 Kudos

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

Former Member
0 Kudos

hi,

Please check this.

DATA pack TYPE p VALUE '12345678'.

WRITE pack NO-GROUPING ROUND 2 DECIMALS 4.

Rewards points if it is useful

former_member434229
Active Participant
0 Kudos

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

Former Member
0 Kudos

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

former_member196280
Active Contributor
0 Kudos

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

Close the thread if your question is answered.

Regards,

SaiRam

Former Member
0 Kudos

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

reward points to all helpful answers

kiran.M

dev_parbutteea
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

hi

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

DATA pack TYPE p VALUE '12345678'.

WRITE : 'answer:' .

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

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

Former Member
0 Kudos

hi,

data : val type p decimals 3 .

data : sel type p decimals 0.

val = 1234.55.

sel = val.

write : sel.

Reward with points if helpful.

Former Member
0 Kudos

Hi,

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

Thanks

Lakshman