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

How Packed decimal works?

Former Member
0 Likes
3,354

Hi

I have this piece of code

REPORT  z_rd_table.

data: var(8) type c,
      num(3) type p DECIMALS 2,
      len type i,
      com type i,
      out type i,
      typ type c.

DESCRIBE FIELD num type typ COMPONENTS com length len in byte MODE OUTPUT-LENGTH out.
num = '12345.78'.
WRITE: / num, typ, com, len, out.

When I execute this code, it gives exception on line num='12345.78' which I can understand because I declared num as 3 bytes long with 2 decimal places.

But when I modify the program to the code below, it works fine though I assumed it should provide exception as per above code.

REPORT  z_rd_table.

data: var(8) type c,
      num(4) type p DECIMALS 2,
      len type i,
      com type i,
      out type i,
      typ type c.

dESCRIBE FIELD num type typ COMPONENTS com length len in byte MODE OUTPUT-LENGTH out.
num = '12345.78'.
WRITE: / num, typ, com, len, out.

Can you please advise how packed decimal works?

(For information I am using SAP 7.00 with unicode. The code is written in IDES environment.)

Edited by: Ritvik Devre on May 25, 2008 5:40 PM

Hi

I have this piece of code

REPORT  z_rd_table.

data: var(8) type c,
      num(3) type p DECIMALS 2,
      len type i,
      com type i,
      out type i,
      typ type c.

DESCRIBE FIELD num type typ COMPONENTS com length len in byte MODE OUTPUT-LENGTH out.
num = '12345.78'.
WRITE: / num, typ, com, len, out.

When I execute this code, it gives exception on line num='12345.78' which I can understand because I declared num as 3 bytes long with 2 decimal places.

But when I modify the program to the code below, it works fine though I assumed it should provide exception as per above code.

REPORT  z_rd_table.

data: var(8) type c,
      num(4) type p DECIMALS 2,
      len type i,
      com type i,
      out type i,
      typ type c.

dESCRIBE FIELD num type typ COMPONENTS com length len in byte MODE OUTPUT-LENGTH out.
num = '12345.78'.
WRITE: / num, typ, com, len, out.

Can you please advise how packed decimal works?

(For information I am using SAP 7.00 with unicode. The code is written in IDES environment.)

Edited by: Ritvik Devre on May 25, 2008 5:40 PM

4 REPLIES 4
Read only

Former Member
0 Likes
1,170

superb find mate...

i was debugging this stuff and found that...

data: num TYPE p LENGTH 1 decimals 2.

This allocates 3 in out put length.

data: num TYPE p LENGTH 2 decimals 2.

This allocates 5 in out put length.

data: num TYPE p LENGTH 3 decimals 2.

This allocates 7 in out put length.

data: num TYPE p LENGTH 4 decimals 2.

This allocates 9 in out put length.

so...when its trying to put '12345.78' (8 char) into num (len 3 dec 2) in gives dump as out put length is 7..

but when we try to '12345.78' (8 char) into num (len 4 dec 2)

it works as out put length is 9...

may be this has something to do with it.

Read only

0 Likes
1,170

Wow.. this is interesting... and out of box..

Keep ABAPing...

Read only

Former Member
0 Likes
1,170

Sorry guys but i figured it out myself how it works by further digging around. Hope it helps!!!.

Depending on the field length len and the number of decimal places dec, the following applies for the value area: (-10(2len -1) +1) / (10(dec)) to (10(2len -1) -1) /(10(+dec)) in steps of 10^(-dec). Values in between this range are rounded off.

Read only

Former Member
0 Likes
1,170

I wish i could reward points to myself.