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 to concatenate a string with spaces

former_member431874
Participant
0 Likes
100,922

Dear experts,

I would like to concatenate a string with three spaces, for example,

CONCATENATE 'X' SPACE SPACE SPACE 'Y' INTO LV_RESULT.

However, the result I got from executing the above statement is not 'X Y' as I want, but rather 'XY'.

I did try

CONCATENATE 'X' '***' 'Y' INTO LV_RESULT.

REPLACE '***' with ' ' INTO LV_RESULT.

still doesn't work.

How can I write ABAP code to archive such a result?

Any idea would be appreciated.

Vitthavat A.

1 ACCEPTED SOLUTION
Read only

Shahid
Product and Topic Expert
Product and Topic Expert
35,352

CONCATENATE 'x' 'y' into lv_string SEPARATED BY space.

Dear experts,

I would like to concatenate a string with three spaces, for example,

CONCATENATE 'X' SPACE SPACE SPACE 'Y' INTO LV_RESULT.

However, the result I got from executing the above statement is not 'X Y' as I want, but rather 'XY'.

I did try

CONCATENATE 'X' '***' 'Y' INTO LV_RESULT.

REPLACE '***' with ' ' INTO LV_RESULT.

still doesn't work.

How can I write ABAP code to archive such a result?

Any idea would be appreciated.

Vitthavat A.

16 REPLIES 16
Read only

Shahid
Product and Topic Expert
Product and Topic Expert
35,353

CONCATENATE 'x' 'y' into lv_string SEPARATED BY space.

Read only

0 Likes
35,351

Dear ssm and koolspy,

thank you for your answer. however, I want THREE spaces between 'X' and 'Y'. Your code will give me only one space.

Read only

Former Member
35,351

Hi,

do not use ' but ` to surround your string (`text ` instead of 'text ').

And then do not use "separeted by".

Best regards,

Oliver

Edited by: Oliver Hütköper on Jul 21, 2011 12:40 PM

Read only

koolspy_ultimate
Active Contributor
0 Likes
35,351

hi

try this


concenate 'x'  'y'  into lv_string seperated by space.

Read only

Shahid
Product and Topic Expert
Product and Topic Expert
0 Likes
35,351

data: lv_string type string.

data: lv_str2 type string.

CONCATENATE 'x' ' ' into lv_string SEPARATED BY space.

CONCATENATE ' ' ' ' into lv_str2 SEPARATED BY space.

CONCATENATE lv_string lv_str2 into lv_str2 SEPARATED BY space.

CONCATENATE lv_str2 'y' into lv_string SEPARATED BY space.

write: lv_string.

Read only

Former Member
0 Likes
35,351

Hi,

Try this.

CONSTANTS lc_str(3) type c VALUE '   '.
DATA lv_string TYPE string.
CONCATENATE 'x' lc_str lc_str 'y' INTO lv_string SEPARATED BY space.
WRITE lv_string.

Regards

HM

Read only

0 Likes
35,351

This message was moderated.

Read only

koolspy_ultimate
Active Contributor
0 Likes
35,351

try this



constants  temp(1) type c value ' '.

DATA lv_string TYPE string.

concatenate  'x'  temp temp 'y' into lv_string separated by space.  " use temp no of times for no of spaces.
" i.e if you want 4 spaces then write temp 3 times.
write:/  lv_string.


Read only

Former Member
0 Likes
35,351

Hi,

Try this


CONCATENATE A space space space B INTO C RESPECTING BLANK. 

Thanks,

Anmol

Read only

former_member302911
Active Participant
35,351

Try RESPECTING BLANKS...

CONCATENATE 'X' SPACE SPACE SPACE 'Y' INTO LV_RESULT RESPECTING BLANKS.

Regards,

Angelo.

Read only

0 Likes
35,351

Worked for me thanks.

Read only

former_member431874
Participant
0 Likes
35,351

solved.

thank you everyone.

i do this:

concatenate IBASIC-KUNNR IBASIC-MATNR into E1KOMG-VAKEY.

lv_len = strlen( E1KOMG-VAKEY ).

lv_shift = 100 - lv_len.

lv_shift = lv_shift - 3.

lv_shift = lv_len + lv_shift.

shift E1KOMG-VAKEY by lv_shift places circular.

concatenate IBASIC-VKORG E1KOMG-VAKEY into E1KOMG-VAKEY.

*while 100 is the length of E1KOMG-VAKEY.

Read only

former_member431874
Participant
0 Likes
35,351

dear Oliver Hütköper and koolspy,

I tried your solutions, and it works.

so i awarded points to you.

anyway, while trying the 'respecting blanks', i got an error:

"".", "IN BYTE MODE", "SEPARATED BY ..." or "IN CHARACTER MODE" expected"

not sure what it means. but it's ok. the problem has been solved.

thanks again.

Read only

Former Member
0 Likes
35,351

Hi,

DATA: lv_str TYPE string, lv_space(5) TYPE c.

CONCATENATE 'abc' 'def' INTO lv_str SEPARATED BY lv_space.

WRITE:/ lv_str.

Ram.

Read only

0 Likes
35,351

if there is thousands of files then?

Read only

0 Likes
35,351
Contants: lv_space(3) type c value '   '.

Concatenate var1 var2 into var3 separated by lv_space.