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 can we insert spaces into string?

Former Member
0 Likes
1,140

Hello everybody,

I have requirement where in i need to insert spcaes into a string based upon a condition.

I have tried using the below code butits not working .

Can anybody suggest me if there is any other way out.

parameter : p_matnr(24).

data : len type i.

len = STRLEN( p_matnr ).

data : length type i.

length = 18 - len.

do length times.

concatenate p_matnr ' ' into p_matnr.

if sy-index = length.

concatenate p_matnr '000010' into p_matnr.

endif.

enddo.

write : p_matnr.

Helpful answers will b rewarded.

Thankx in advance.

Sanghamitra.

1 ACCEPTED SOLUTION
Read only

younes_bouaouad
Explorer
0 Likes
975

Hi,

what do you want to do exactly?

is it that way :

from a string like "xxxxxxxxxxx" with length lesser than or equal to 18, you would like to have a string "xxxxxxxxxxx 000010" on 24 chars? with enough spaces between the original string and the 6 chars long string enqueued?

if that's your issue, you could use overlay, you overlay a string of 24 chars, begining with 18 spaces and ending with your '000010'.

Hope that helps.

6 REPLIES 6
Read only

Former Member
0 Likes
975

concatenate ' ' var into var separated by space.

Read only

Former Member
0 Likes
975

Hi,

Use Separated by Space.

<b>concatenate p_matnr '000010' into p_matnr separated by space.</b>

Regards,

Padmam.

Read only

Former Member
0 Likes
975

solved....

i solved the issue myself by adding RESPECTING BLANKS at the end of concatenate statement.

This is the code.

parameter : p_matnr like mara-matnr.

data : str(24).

concatenate p_matnr '000010' into str respecting blanks.

write 😕 str.

Regards,

sanghamitra.

Read only

0 Likes
975

thanks a lot for ur response...

but even b4 that i could solve that....

have awarded points..

Read only

Former Member
0 Likes
975

parameter : p_matnr(24).

data : len type i.

len = STRLEN( p_matnr ).

data : length type i.

data : v_ch,

pat(18).

length = 18 - len.

do length times.

concatenate v_ch space into pat separated by space.

if sy-index = length.

concatenate p_matnr '000010' into p_matnr separated by pat.

endif.

enddo.

regards

shiba dutta

Read only

younes_bouaouad
Explorer
0 Likes
976

Hi,

what do you want to do exactly?

is it that way :

from a string like "xxxxxxxxxxx" with length lesser than or equal to 18, you would like to have a string "xxxxxxxxxxx 000010" on 24 chars? with enough spaces between the original string and the 6 chars long string enqueued?

if that's your issue, you could use overlay, you overlay a string of 24 chars, begining with 18 spaces and ending with your '000010'.

Hope that helps.