2008 May 25 4:39 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
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
2008 May 25 7:59 PM
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.
2008 May 25 8:14 PM
Wow.. this is interesting... and out of box..
Keep ABAPing...
2008 May 25 8:26 PM
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.
2008 May 25 8:29 PM
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |