‎2008 Dec 29 3:29 PM
Hi there,
I have to write a DEC-variable into a clike-structure with leading zeros. How can I achive this? I know now that I can use the OVERLAY-statment to get the leading zeros, but I don't know at runtime how long the DEC field is, so how can I achieve the following example:
Ex 1: 7 DEC 3 with value "12,123"
--> 0012.123
DEC 13 DEC 3 with value "153,25"
--> 0000000153.250
Can anyone give me a hint?
Thanks a lot. Help will be rewarded.
With kind regards
Markus
‎2008 Dec 29 4:57 PM
You can only use OVERLAY or TRANSLATE or any other only on data type C, N, D and T. So you have to move your values first to your target field and than do the manipulation and I would suggest use the TRANSLATE .. using to fill the leading zero.
Try like this:
data: p_amt(7) type p decimals 3.
data: l_target type char30. " CHAR like Structure field
p_amt = '123.456'.
write: p_amt to l_target right-justified.
translate l_target using ' 0'.
write: / p_amt.
write: / l_target.
Regards,
Naimesh Patel
‎2008 Dec 29 3:36 PM
‎2008 Dec 29 3:38 PM
That doesn't work with non-clike variables...
And the variable I use is of type "P"
‎2008 Dec 29 3:47 PM
try this way
DATA: lv_p TYPE p DECIMALS 3 VALUE '2.998'.
DATA: lv_len TYPE i.
DESCRIBE FIELD lv_p LENGTH lv_len IN BYTE MODE.
do
"<<<<<add zeros untill u fill it up...
endo.
‎2008 Dec 29 3:49 PM
Is it perhaps possible that you give me a more detailled example of the coding you mentioned? I don't really know how to fill these zeros...
Thank you so much.
Kind regards
Markus
‎2008 Dec 29 4:50 PM
this looks like a limitation..
either you have to change the type and use ...
*SHIFT lv_p RIGHT DELETING TRAILING space.
*SHIFT lv_p LEFT DELETING LEADING space.
*TRANSLATE lv_p USING ' 0'.
‎2008 Dec 29 3:41 PM
Hi,
Try to utilize the FM: BKK_ACCNT_ADD_LEADING_ZERO.
i hope it will give some idea to you.
‎2008 Dec 29 4:57 PM
You can only use OVERLAY or TRANSLATE or any other only on data type C, N, D and T. So you have to move your values first to your target field and than do the manipulation and I would suggest use the TRANSLATE .. using to fill the leading zero.
Try like this:
data: p_amt(7) type p decimals 3.
data: l_target type char30. " CHAR like Structure field
p_amt = '123.456'.
write: p_amt to l_target right-justified.
translate l_target using ' 0'.
write: / p_amt.
write: / l_target.
Regards,
Naimesh Patel