Application Development 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: 

Concatenate with new-line

Former Member
0 Kudos
26,224

Hi,

i got a Small problem. I have to Concatenate two Strings and Separated them with a New Line but i couldn't find anything to get this done.

My test Code looks like this :

DATA: test1 TYPE String,

test2 TYPE String,

test3 TYPE string.

test1 = 'Hallo'.

test2 = 'du da'.

CONCATENATE test1 test2 INTO test3 SEPARATED BY space.

WRITE test3.

This works so far but i need to replace space with something to get a new Line.

Maybe someone had an idea.

Greetings

Moritz

1 ACCEPTED SOLUTION

Former Member
6,300

Hi Mortiz,

Please check below:


data: l_cr(1) type c value cl_abap_char_utilites=>cr_lf,
      l_lf(1) type c value cl_abap_char_utilities=>linefeed.

One of the above will certainly help you. Am not on SAP now to check the same. Use this for concatenating.


  CONCATENATE str1 str2 INTO out SEPARATED BY l_cr.
  CONCATENATE str1 str2 INTO out SEPARATED BY l_lf.

Kind Regards

Eswar

15 REPLIES 15

Former Member
6,301

Hi Mortiz,

Please check below:


data: l_cr(1) type c value cl_abap_char_utilites=>cr_lf,
      l_lf(1) type c value cl_abap_char_utilities=>linefeed.

One of the above will certainly help you. Am not on SAP now to check the same. Use this for concatenating.


  CONCATENATE str1 str2 INTO out SEPARATED BY l_cr.
  CONCATENATE str1 str2 INTO out SEPARATED BY l_lf.

Kind Regards

Eswar

0 Kudos
6,300

Hmm,

i didn't have the Class cl_abap_char_utilities :/. We got a SAP R3 4.6 C. i could not find any similar class so far :-/.

greetings

Moritz

0 Kudos
6,300

Hi,

Try this..

DATA: V_HEX TYPE X VALUE '0D'. "Carriage return.

DATA: V_CHAR(50).

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

Regards,

Satish

0 Kudos
6,300

Mortiz,

In that case you need to declare as below.

>data: l_tab(1) type X value '09'

Value 09 denoted tab character, similarly you need to get the value for NEW LINE.

Sorry cant remember the exact code. Try to get the ascii character for the same.

Regards

Eswar

0 Kudos
6,300

Thanks for your help,

but both "Code" brings me a '#' between the two Strings.

Im a little bit Confused :-(.

Greetings

Moritz

0 Kudos
6,300

Hi Mortiz

If you are checking in debug mode, it will be visible as '#'.

Try downloading the same to a file and then test the output.

Regards

Eswar

0 Kudos
6,300

Hi,

Try this

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

DATA: V_CHAR(50).

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

Regards,

Satish

0 Kudos
6,300

Thanks a lot this solved the Problem,

Greetings

Moritz

0 Kudos
6,300

I am not using 7.4 version can help me with same code in ECC

matt
Active Contributor
0 Kudos
6,300

The coding works on 7.31.

0 Kudos
6,300

vinay_krishna and it probably works in version ABAP 4.6C too. Please start a new question if you want discussing, people usually don't reply on comments on old questions. Good bye.

Former Member
0 Kudos
6,300

Hi,

u just try like this

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.

rgds,

bharat.

Former Member
0 Kudos
6,300

hi,

try it

data: l_cr(1) type c value cl_abap_char_utilities=>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.

L.Velu

0 Kudos
6,300

Hmm if i download it to a file it works, but the Problem is i have to show the result in SAP.

In a Message Box and there i got the "#" or for sy-uline(5) i got "-----" :-/.

So i seperate the two Strings with a space.

This works but dint look nice, but its the only way to solve it at the moment.

Thanks for your great help.

Greetings

Moritz

former_member230674
Contributor
6,300

Hai

There is small error in this code,

when using concatenate operator ,

CONCATENATE C1 C2 ....CN INTO STR1 BY H.

H should be Character type either C ,N,D,T or String.

In your program,

you are declaring line_br(2) type X.

so, it gives that error.

you should correct your code in either way like

DATA: line_br(4) TYPE C VALUE '0D0A'.

OR

DATA: line_br TYPE STRING VALUE '0D0A'.

DATA: v_line TYPE string.

CONCATENATE 'LINE1' 'LINE2' INTO v_line SEPARATED BY line_br.

Then it works.

if it useful, reward points.

Thank you,

G.V.K.Prasad