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 new line into a string while displaying

0 Likes
14,639

Hi All,

how to concatenate a newline to a string variable.

for ex:

input:

var1 = 'abc'.

var2 = 'def'.

var3 = 'ghi'.

varout = concatenate the above 3 variables seperated by new line (not space).

so that, when i write varout to display, it should display like:

abc

def

ghi

not like abcdefghi.

Regards

Dileepkumar VT

1 ACCEPTED SOLUTION
Read only

nomssi
Active Contributor
0 Likes
6,635

Hello Dileepkumar,

check if you are on 7.02.

In your case, you could do

DATA lf type c LENGTH 1.

lf |\n|.


varout = var1 && lf && var2 & lf && var3 && lf.

or

varout = |{ var1 }\n{ var2 }\n{ var3 }\n|

or use cl_abap_char_utilities=>newline.

regards,

JNN

7 REPLIES 7
Read only

former_member201285
Active Participant
0 Likes
6,635

You can use the constant CL_ABAP_CHAR_UTILITIES=>NEWLINE

However, this won't work for list outputs. It can be used for writing into files e.g.

Regards,

Ulrich

Read only

srinivasan_vinayagam
Active Contributor
0 Likes
6,635

Hello,

concatenate var1, var2, var3 into varout respecting spaces.

and try  RESPECTING BLANKS

https://help.sap.com/abapdocu_70/en/ABAPCONCATENATE.htm

Read only

nomssi
Active Contributor
0 Likes
6,636

Hello Dileepkumar,

check if you are on 7.02.

In your case, you could do

DATA lf type c LENGTH 1.

lf |\n|.


varout = var1 && lf && var2 & lf && var3 && lf.

or

varout = |{ var1 }\n{ var2 }\n{ var3 }\n|

or use cl_abap_char_utilities=>newline.

regards,

JNN

Read only

Clemenss
Active Contributor
0 Likes
6,635

Hi dileepkumar tatti,

if you use ABAP statement WRITE varout you will never get any linebreaks except when the line length is exceeded.

With WRITE, / is the new-line, i.e. WRITE: / var1, / var2, / var3 will give the desired result.

Note: Output using WRITE will display all control and ohther non-display-characters as #,

As to be found in the link already given:

Where to use a line feed character in ABAP

First, where  to use it not. You cannot use a line feed character or any other control character in classical list programming. The following line


WRITE |aaaa\nbbbbb|.

produces an output like aaaa#bbbbb.


Regards


Clemens

Read only

0 Likes
6,635

Hi Li,Nomssi.

Thank you for your response.

Thing is, i am displaying the variable into a mail body. so before i call function to send mail i want this variable to be very ready with new lines fed in between.

This variable is used for holding the values of another dynamic variable which will have different values each time a new iteration of loop begins.

Requisite:

Need to display all the variables (don’t know how many variables-as they are derived dynamically).

These variables are to be concatenated in one single variable with a new line feed between them.

Ex:

IT:

F1

F2

F3

a

..

..

b

..

..

u

v

c

d

z

Data: var type string.

LOOP AT IT into WA.

             Var = wa-f1.

                concatenate var into var1 separated by space.

ENDLOOP.

Write: var1.

Output:

              ab uv cd z

what needed is:

                                                                                              

                                                                                                ab

                                                                                                uv

                                                                                                cd

                                                                                                z

Note that I have to use my write statement outside the loop only. If I was allowed to use it inside the loop, then displaying it in new line would have been easy just using ‘/’ in write statement.

Actually I am displaying this variable in a mail body content. So I cannot use write statement there as I use it for ABAP output screen.

And also note that I am not sure what is the total number of rows of internal table in the above example. Hence I cannot use SPLIT keyword also.

I am not sure if it is possible in Classical ABAP, but unfortunately thats how is needed.

Regards

Dileep VT

Read only

0 Likes
6,635

Hello,

If you want add new line for mail body, use <br>. This is HTML tag.

Read only

0 Likes
6,635

Hi,

try this :

DATA :      lv_lines TYPE I,

                  lv_var      TYPE STRING,

                 lv_count TYPE I.

lv_lines = LINES( it[] ).

LOOP AT it INTO wa.

      CONCATENATE lv_var wa-f1 INTO lv_var.

     ADD 1 TO lv_count.

     IF lv_count = 2 OR sy-tabix = lv_lines.

          WRITE / LV_VAR.

         

          CLEAR : lv_var,

                         lv_count

     ENDIF.

ENDLOOP.

Regards,

Ashish