‎2014 Nov 17 2:09 PM
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
‎2014 Nov 17 2:42 PM
‎2014 Nov 17 2:26 PM
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
‎2014 Nov 17 2:35 PM
Hello,
concatenate var1, var2, var3 into varout respecting spaces.
and try RESPECTING BLANKS
‎2014 Nov 17 2:42 PM
‎2014 Nov 17 8:13 PM
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:
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
‎2014 Nov 18 7:52 AM
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
‎2014 Nov 18 8:32 AM
Hello,
If you want add new line for mail body, use <br>. This is HTML tag.
‎2014 Nov 18 10:48 AM
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