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

Problem in concatenating strings..

Former Member
0 Likes
1,428

Hi All,

I want to concatenate two or more strings using the CONCATENATE statement so that they are joined at new lines. Example -

If the code is :-

v_str1 = 'first line'.

v_str2 = 'second line'.

v_str3 = 'third line'.

"Required statement to concatenate v_str1, v_str2 and v_str3 into v_str.

WRITE:/ v_str.

Then the output is :

first line

second line

third line

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,387

I dont think you can do that way.

Try this way.

types: begin of ty_string,
             string type string,
          end of ty_string.

data: wa_string type ty_string,
        t_string type table of ty_string.

wa_string-string = 'first line'.
append wa_string to t_string.

similarly for others.

loop at t_string into wa_string.
write:/wa_strin-string.
endloop.

Regards,

Shailaja

12 REPLIES 12
Read only

Former Member
0 Likes
1,388

I dont think you can do that way.

Try this way.

types: begin of ty_string,
             string type string,
          end of ty_string.

data: wa_string type ty_string,
        t_string type table of ty_string.

wa_string-string = 'first line'.
append wa_string to t_string.

similarly for others.

loop at t_string into wa_string.
write:/wa_strin-string.
endloop.

Regards,

Shailaja

Read only

0 Likes
1,387
CONCATENATE abc def xyz .... into abcd 
SEPARATED BY CL_ABAP_CHAR_UTILITIES=>NEWLINE.

use this...

NEWLINE separates the elements by a new line.

Read only

0 Likes
1,387

Hi,

Thanks for your reply. But I do not want to display the concatenated string using the WRITE statement. I need to store the concatenated string in a variable (say v_str in this case) and then display the value of v_str as MESSAGE v_str TYPE 'I'.

Read only

0 Likes
1,387

when u save it in csv.. it will create new lines for you.

Read only

0 Likes
1,387

Use FM FITP_POPUP_TO_INFORM.

Regards,

Shailaja

Read only

0 Likes
1,387

use POPUP_TO_INFORM

CALL FUNCTION 'POPUP_TO_INFORM'
  EXPORTING
    titel         = 'This is title'
    txt1          = 'first line'
    txt2          = '2nd line'
   TXT3          = '3rd line'
*   TXT4          = ' '
          .

Read only

Former Member
0 Likes
1,387

Hi,

Instead of concatenation; append them in an internal table and then loop on it and write the data.

Concatenate will not be able to write in the required format.

Alternatively what you can do is concatenate separated by space and then split at space into an internal table oftype string and the write the data by looping on the table.

Regards,

Ankur Parab

Read only

Former Member
0 Likes
1,387

You cannot do like this using concatenate statment...either you write three write statement or put all strings in table and print.

regards

vivek

Read only

Former Member
0 Likes
1,387

Hi,

If you have to display all strings in new lines, then what is the use of concatenate statement? why can't you write like this.

WRITE:/ v_str1,
      / v_str2,
      / v_str3.

Regards

Vishnu Gupta

Read only

Former Member
0 Likes
1,387

Hi Anirban,

Use the below code.

data: v_str1 type string value 'first line',

v_str2 type string value 'second line',

v_str3 type string value 'third line',

v_str type string.

concatenate v_str1 v_str2 v_str3 into v_str separated by ','.

WRITE:/ v_str.

clear: v_str1, v_str2, v_str3.

split v_str at ',' into v_str1 v_str2 v_str3.

write:/5 v_str1,

/5 v_str2,

/5 v_str3.

Regards,

Kumar Bandanadham

Read only

Former Member
0 Likes
1,387

Hi,

DATA: V_STR1 TYPE STRING,
      V_STR2 TYPE STRING,
      V_STR3 TYPE STRING,
       V_STR TYPE STRING.

CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
CONSTANTS: CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>NEWLINE.


V_STR1 = 'first line'.
V_STR2 = 'second line'.
V_STR3 = 'third line'.

CONCATENATE V_STR1 CON_CRET V_STR2 CON_CRET  V_STR3  INTO V_STR.

WRITE:/ V_STR.

Read only

Former Member
0 Likes
1,387

Hi,

data: v_str1 type string value 'first line',

v_str2 type string value 'second line',

v_str3 type string value 'third line',

v_str type string.

data: v_text like POPUPTEXT occurs 10 with header line.

data: v_ans type char1.

v_text-topofpage = 'X'.

append v_text.

clear v_text.

v_text-topofpage = 'X'.

v_text-text = 'You want to proceed or not?'.

append v_text.

clear v_text.

v_text-topofpage = 'X'.

append v_text.

clear v_text.

v_text-text = v_str1.

append v_text.

v_text-text = v_str2.

append v_text.

v_text-text = v_str3.

append v_text.

CALL FUNCTION 'DD_POPUP_WITH_LIST'

EXPORTING

TITEL = 'Information'

LISTTITEL = 'Strings'

START_COLUMN = 1

START_ROW = 1

END_COLUMN = 50

END_ROW = 20

IMPORTING

ANSWER = v_ans

TABLES

lines = v_text

.

if v_ans = 'N'.

write:/ 'cancelled'.

else.

write:/ 'Proceed'.

endif.