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

String Concatenation in ABAP

Former Member
61,429

Hi Experts!!

I want to concatenate two strings but there should be change in line after 1st string. Is it possible to create a string that concatenates the two strings separated with a new line.

For example string1 and string2 is to be concatenated in string3 as:-

string1

string2

Thanks in advance..

Prabhas Jha

1 ACCEPTED SOLUTION
Read only

Former Member
17,214

prabha,

Try this

DATA: NEWLINE(2) TYPE X VALUE '0D0A'

DATA: V_CHAR(50).

CONCATENATE LINE1 LINE2 INTO V_CHAR SEPARATED BY NEWLINE.

(OR)

DATA: test1 TYPE String,

test2 TYPE String,

test3 TYPE string.

test1 = 'Hallo'.

test2 = 'du da'.

CONCATENATE test1 sy-uline(5) test2 INTO test3 SEPARATED BY space.

WRITE test3.

Don't forget to reward if useful...

15 REPLIES 15
Read only

abdulazeez12
Active Contributor
0 Likes
17,214

Hi

DATA: gv_line_space(256) type c.

CONCATENATE string1 gv_line_space string2 into string3.

Write: string3.

Just check the output..u need to adjust the width of gv_line_space so that the output comes as desired by you.

Cheers

Shakir

Read only

Former Member
0 Likes
17,214

hi,

find out the length of the string1 then minus it through 256

then concatenate this much spaces back to the string1 and then concatenate string2 back to string1.

then try to display the string1.

your problem will be solved.

thanks

Dharmishta

Read only

Former Member
17,215

prabha,

Try this

DATA: NEWLINE(2) TYPE X VALUE '0D0A'

DATA: V_CHAR(50).

CONCATENATE LINE1 LINE2 INTO V_CHAR SEPARATED BY NEWLINE.

(OR)

DATA: test1 TYPE String,

test2 TYPE String,

test3 TYPE string.

test1 = 'Hallo'.

test2 = 'du da'.

CONCATENATE test1 sy-uline(5) test2 INTO test3 SEPARATED BY space.

WRITE test3.

Don't forget to reward if useful...

Read only

0 Likes
17,214

for this u should dynamically calculate the line width as per 1st strings value.

And in the concatenation part the line space should be also calculated as per the line width calculation mentioned above.

Read only

Former Member
0 Likes
17,214

Hi all..

I tried using a new string ,string3(200) and concatenated with the strings.

Concatenate string1 string4(200) string2 into string3.

But in the output it is not adding the spaces. In fact it just ignores string4.

What can be the reason..I have to concatenate by this method.

Thanks..

Prabhas

Read only

athavanraja
Active Contributor
0 Likes
17,214

concatenate

string1 string2 into result_string separated by cl_abap_char_utilities=>cr_lf .

Read only

Former Member
0 Likes
17,214

hi Durairaj,

In place of creating a new line, ## has been inserted in between the strings,if i use cl_abap_char_utilities=>cr_lf .

Read only

0 Likes
17,214

if you write the string to ABAP list or view the string in debugger, thats how it will show up. however if you pass this string to any text editor it would properly split it and show it in two lines.

Regards

Raja

Read only

0 Likes
17,214

Hi,

Do like this

data: l_cr(1) type c value cl_abap_char_utilites=>cr_lf,

l_lf(1) type c value cl_abap_char_utilities=>linefeed.

CONCATENATE str1 str2 INTO out SEPARATED BY l_cr.

CONCATENATE str1 str2 INTO out SEPARATED BY l_lf.

If your Version is 4.6C, do like this

DATA: NEWLINE(2) TYPE X VALUE '0D0A'

DATA: V_CHAR(50).

CONCATENATE 'LINE1' 'LINE2' INTO V_CHAR SEPARATED BY NEWLINE.

Regards,

Satish

Read only

0 Likes
17,214

hi...

I tried using both the methods..

for the first method,

cl_abap_char_utilites=>cr_lf is not recognized by system.

for second method my version is ecc6.0, so it is unable to recognize type 'X'.

i tried by concatenating a blank variable with space...But that does not work as well!!

Read only

Former Member
0 Likes
17,214

Hi Experts,

How to Use the Concatenation Statement.

Regards,

Santosh Ballyapelli

Read only

0 Likes
17,214

why not read your ABAP Help (F1) for the concatenate statement?

Read only

Former Member
0 Likes
17,214

For example string1 and string2 is to be concatenated in string3 as:-

string1

string2

Why do you want to concatenate?

Take 2 separate strings in your operations instead of concatenating.

eg:

write:/ String1

write:/ String2

Read only

Former Member
0 Likes
17,214

Nothing to Do.

Just Write 'SEPARATED BY SPACE'  At the end of Concatenate statement.

thanks.

reward if it is useful.

Read only

Former Member
0 Likes
17,214

This message was moderated.