- SAP Community
- Groups
- Interest Groups
- Application Development
- Discussions
- Floating point Number & Packed Number

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.

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Floating point Number & Packed Number

Former Member

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

08-31-2007 10:52 AM

Hai can anyone tell me what is the difference in using floating point & packed Number .

when it will b used ?

- SAP Managed Tags:
- ABAP Development

1 ACCEPTED SOLUTION

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

08-31-2007 11:40 AM

Hi,

The difference is as:

Packed numbers arithmetic:

All P fields are treated as whole numbers. Calculations involving decimal places require additional programming to include multiplication or division by 10, 100, ... . The DECIMALS specification with the DATA declaration is effective only for output with WRITE .

If, however, fixed point arithmetic is active, the DECIMALS specification is also taken into account. In this case, intermediate results are calculated with maximum accuracy (31 decimal places). This applies particularly to division.

For this reason, you should always set the program attribute "Fixed point arithmetic".

Example

DATA P TYPE P.

P = 1 / 3 * 3.

Without "fixed point arithmetic", P has the value 0, since " 1 / 3 " is rounded down to 0.

With fixed point arithmetic, P has the value 1, since the intermediate result of " 1 / 3 " is 0.333333333333333333333333333333.

Note

Floating point arithmetic

With floating point arithmetic, you must always expect some loss of accuracy through rounding errors (ABAP/4 number types ).

Rewards points if usefull........

- SAP Managed Tags:
- ABAP Development

4 REPLIES 4

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

08-31-2007 11:40 AM

Hi,

The difference is as:

Packed numbers arithmetic:

All P fields are treated as whole numbers. Calculations involving decimal places require additional programming to include multiplication or division by 10, 100, ... . The DECIMALS specification with the DATA declaration is effective only for output with WRITE .

If, however, fixed point arithmetic is active, the DECIMALS specification is also taken into account. In this case, intermediate results are calculated with maximum accuracy (31 decimal places). This applies particularly to division.

For this reason, you should always set the program attribute "Fixed point arithmetic".

Example

DATA P TYPE P.

P = 1 / 3 * 3.

Without "fixed point arithmetic", P has the value 0, since " 1 / 3 " is rounded down to 0.

With fixed point arithmetic, P has the value 1, since the intermediate result of " 1 / 3 " is 0.333333333333333333333333333333.

Note

Floating point arithmetic

With floating point arithmetic, you must always expect some loss of accuracy through rounding errors (ABAP/4 number types ).

Rewards points if usefull........

- SAP Managed Tags:
- ABAP Development

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

08-31-2007 11:43 AM

<b>Packed numbers</b> - type P

Type P data allows digits after the decimal point. The number of decimal places is generic, and is determined in the program. The value range of type P data depends on its size and the number of digits after the decimal point. The valid size can be any value from 1 to 16 bytes. Two decimal digits are packed into one byte, while the last byte contains one digit and the sign. Up to 14 digits are allowed after the decimal point. The initial value is zero. When working with type P data, it is a good idea to set the program attribute Fixed point arithmetic.Otherwise, type P numbers are treated as integers.

You can use type P data for such values as distances, weights, amounts of money, and so on.

<b>Floating point numbers</b> - type F

The value range of type F numbers is 1x10***-307 to 1x10***308 for positive and negative numbers, including 0 (zero). The accuracy range is approximately 15 decimals, depending on the floating point arithmetic of the hardware platform. Since type F data is internally converted to a binary system, rounding errors can occur. Although the ABAP processor tries to minimize these effects, you should not use type F data if high accuracy is required. Instead, use type P data.

You use type F fields when you need to cope with very large value ranges and rounding errors are not critical.

Using I and F fields for calculations is quicker than using P fields. Arithmetic operations using I and F fields are very similar to the actual machine code operations, while P fields require more support from the software. Nevertheless, you have to use type P data to meet accuracy or value range requirements.

reward if useful

- SAP Managed Tags:
- ABAP Development

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

08-31-2007 12:09 PM

- SAP Managed Tags:
- ABAP Development

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

08-31-2007 12:16 PM

Hi vasudevan,

This link will give detail descrition abt datatypes.

http://help.sap.com/saphelp_webas620/helpdata/en/fc/eb3434358411d1829f0000e829fbfe/content.htm

Data Type Code Length Description

b 1 1-byte integer

C 1 - ? Character string

D 8 Date (yyyymmdd)

F 8 Floating point number

I 4 4-byte integer

N 1 - ? Digits-only character string

P Binary Coded Decimal (packed) number

s 2 2-byte integer

T 6 Time (hhmmss)

X 1 - ? Raw data

INTLEN tells us the number of bytes used by this field; DECIMALS the number of decimals for packed and floating point numbers.

regards,

Kumar.

- SAP Managed Tags:
- ABAP Development