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

Dynamic overlay

Former Member
0 Likes
1,192

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

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
1,003

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

7 REPLIES 7
Read only

former_member156446
Active Contributor
0 Likes
1,003

use

CONVERSION_EXIT_ALPHA_INPUT

Read only

0 Likes
1,003

That doesn't work with non-clike variables...

And the variable I use is of type "P"

Read only

0 Likes
1,003

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.

Read only

0 Likes
1,003

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

Read only

0 Likes
1,003

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'.

Read only

Former Member
0 Likes
1,003

Hi,

Try to utilize the FM: BKK_ACCNT_ADD_LEADING_ZERO.

i hope it will give some idea to you.

Read only

naimesh_patel
Active Contributor
0 Likes
1,004

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