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: 

Packed Datatype

Former Member
0 Kudos

What exactly is a packed datatype in ABAP?

1 ACCEPTED SOLUTION

Former Member

hi check this..

when u use the decimals in the type f it will give the all the decimals even though it is not necessary.. and we cannot restrict the decimals in the float type ...to get the proper decimals we use the type packed decimal..

regards,

venkat

4 REPLIES 4

Former Member
0 Kudos

Hi,

For the ABAP types c, n, p and x, the length of the data type dtype must be specified by entering a numeric literal or a numeric constant len within the interval limits from the table of predefined ABAP types. For all other ABAP types, the length is determined by the value in the table of predefined ABAP types and no length can be specified in len.

The length len is either specified in parentheses directly after the type name dtype, or since release 6.10, after the addition LENGTH.

If the addition DECIMALS is used, for the ABAP type p, the number of decimal places must be determined by specifying a numeric literal or a numerical constant dec from the table of predefined ABAP types, within the interval limits. For the decimal separator to be taken into account in operations involving packed numbers, the program attribute 'fixed point arithmetic' must be set. Otherwise, the addition DECIMALS only affects the output format of lists.

Note:

The specification of TYPE abap_type can be omitted. The type is then implicitly set to the standard type c. Outside of classes or interfaces, for the ABAP types c, n, p and x, the specification of len or dec can also be omitted. The new type dtype is then set to the standard length from the table of predefined ABAP types, and for p, is set to zero decimal places.

Example:

These statements create three elementary data types that are local to the program. Values for the unspecified technical properties of the predefined types c and p are specified.

TYPES: text10 TYPE c LENGTH 10,

text20 TYPE c LENGTH 20,

result TYPE p LENGTH 8 DECIMALS 2.

Former Member
0 Kudos

Hi Srk_s,

Data type p for packed numbers has a value range that depends on their length and the number of decimal places. Data objects of type p can be 1 to 16 bytes long, with two decimal places packed into each byte, and one decimal digit and the sign packed into the last byte. There can be up to 14 decimal places. You cannot specify packed numbers with decimal places directly in the program. Instead, you have to use text literals whose contents can be interpreted as a packed number, that is, contains a number in mathematical or commercial notation. The scientific notation is not permitted unless it can be interpreted as a mathematical notation.

Auxiliary fields for intermediate results in arithmetic expressions of calculation type p are always 16 bytes long and can thus hold up to 31 decimal places. Before an overflow, an arithmetic expression is calculated again with auxiliary fields that are twice as large or 63 decimal places.

If you are using packed numbers, you should always set the program attribute fixed point arithmetic as only this ensures that the decimal point is correctly calculated. Otherwise, all numbers are specified as integers and all intermediate results for the next integer are rounded. If fixed point arithmetic is not set, the decimal places defined for the number only appear when outputting with WRITE.

Calculations using calculation type p are performed using fixed point arithmetic. In other words, a calculation is performed "commercially", similarly to using a pocket calculator or paper and pencil. Type p is typically used for sizes such as lengths, weights and sums of money.

Hope this helps.

Benedict

Former Member

hi check this..

when u use the decimals in the type f it will give the all the decimals even though it is not necessary.. and we cannot restrict the decimals in the float type ...to get the proper decimals we use the type packed decimal..

regards,

venkat

0 Kudos

thank u one and all.

My query is answered.