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

add 0 at left

Former Member
0 Likes
881

hi guys,

i need to fill a field with left 0s.

example.

data: num(10).

data: len type p,

data: n type n.

num = '12345'. " and i want '0000012345'

describe field num into len.

n = 10 - len.

shift num right by n places.

do n times.

replace space with '0' into num

enddo.

this will work, my problem is that describe field always give 10, and i need exactly the number of positions filled.

any ideas?

tks in advance

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
789

hi,

you can use STRLEN for determining the actual length of the string.

length = STRLEN( string ).

You can also use conversion exit for this: FM CONVERSION_EXIT_ALPHA_INPUT will fill the string with leading zeros (irrelevant how much you actually need)

hope this helps

ec

3 REPLIES 3
Read only

JozsefSzikszai
Active Contributor
0 Likes
790

hi,

you can use STRLEN for determining the actual length of the string.

length = STRLEN( string ).

You can also use conversion exit for this: FM CONVERSION_EXIT_ALPHA_INPUT will fill the string with leading zeros (irrelevant how much you actually need)

hope this helps

ec

Read only

Former Member
0 Likes
789

Hello,

Define a character field of length 10.

Move the value of num field to this character field.

Pass this character field to the function module 'CONVERSION_EXIT_ALPHA_INPUT'

this will give you a 10 character string with the leading zeroes.

cheers,

Sushil Joshi

Read only

Former Member
0 Likes
789

Hi Javier,

Try the following.

data:

w_strln type i,

w_str1(10) type n,

w_places type i.

w_strln = strlen(w_str).

w_places = 10 - w_strln.

do w_places times.

concatenate '0' w_str into w_str1.

enddo.

Hope this helps you.

Regards,

Chandra Sekhar