Application Development and Automation 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: 
Read only

Fixed point arithmetic

Former Member
0 Likes
1,469

let me know the above.

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
989

<copy&paste_and_everything_else_removed_by_moderator>

Edited by: Julius Bussche on Sep 3, 2008 9:14 AM

2 REPLIES 2
Read only

Former Member
0 Likes
990

<copy&paste_and_everything_else_removed_by_moderator>

Edited by: Julius Bussche on Sep 3, 2008 9:14 AM

Read only

Former Member
0 Likes
989

Hi Bhanu,

For calculations in business applications, use packed numbers. The program attribute Fixed point arithmetic affects calculations using packed numbers.

If the program attribute Fixed point arithmetic is not set, type P fields are interpreted as integers without decimal places. The decimal places that you specify in the DECIMALS addition of the TYPES or DATA statement only affect how the field is formatted in the WRITE statement.

DATA: PACK TYPE P DECIMALS 2.

PACK = '12345'.

WRITE PACK.

If the program attribute Fixed point arithmetic is not set, the output is as follows:

123.45

If the program attribute Fixed point arithmetic is set, the output is as follows:

12,345.00

If the Fixed point arithmetic attribute is set, the decimal places are also taken into account in arithmetic operations. Calculations with packed numbers in ABAP use the same arithmetic as a pocket calculator. Intermediate results are calculated using up to 31 digits (before and after the decimal point). You should therefore always set the Fixed point arithmetic attribute when you use type P fields.

DATA: PACK TYPE P.

PACK = 1 / 3 * 3.

WRITE PACK.

If you have not set the Fixed point arithmetic attribute, the result is 0, since the calculation is performed using integer accuracy, and the result is therefore rounded internally to 0.

If the program attribute Fixed point arithmetic is set, the result is 1 because the result of the division is stored internally as 0.333333333333333333333333333333 with an accuracy of up to 31 digits.

<removed_by_moderator>

kiran.M

Edited by: Julius Bussche on Aug 20, 2008 5:50 PM