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

Former Member
0 Kudos

Hi,

I am trying to combinee 2 strings.

I am getting the error that w_str1 is not defined.

W_STR1='THIS IS'.

W_STR2='A BOOK'.

CONCATENATE W_STR1, W_STR2 INTO W_STR3.

WRITE:/ W_STR3.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

The CONCATENATE statement combines two or more separate strings into one.

CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].

This statement concatenates the character fields <c1> to <cn> and assigns the result to <c>. The

system ignores spaces at the end of the individual source strings.

The addition SEPARATED BY <s> allows you to specify a character field <s> which is placed in

its defined length between the individual fields.

If the result fits into <c>, SY-SUBRC is set to 0. However, if the result has to be truncated, SYSUBRC

is set to 4.

DATA: C1(10) VALUE 'Sum',

C2(3) VALUE 'mer',

C3(5) VALUE 'holi ',

C4(10) VALUE 'day',

C5(30),

SEP(3) VALUE ' - '.

CONCATENATE C1 C2 C3 C4 INTO C5.

WRITE C5.

CONCATENATE C1 C2 C3 C4 INTO C5 SEPARATED BY SEP.

WRITE / C5.

Output:

Summerholiday

Sum - mer - holi - day

In C1 to C5, the trailing blanks are ignored. The separator SEP retains them.

REgards,

Bhaskar

10 REPLIES 10

Former Member
0 Kudos

Hi,

The CONCATENATE statement combines two or more separate strings into one.

CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].

This statement concatenates the character fields <c1> to <cn> and assigns the result to <c>. The

system ignores spaces at the end of the individual source strings.

The addition SEPARATED BY <s> allows you to specify a character field <s> which is placed in

its defined length between the individual fields.

If the result fits into <c>, SY-SUBRC is set to 0. However, if the result has to be truncated, SYSUBRC

is set to 4.

DATA: C1(10) VALUE 'Sum',

C2(3) VALUE 'mer',

C3(5) VALUE 'holi ',

C4(10) VALUE 'day',

C5(30),

SEP(3) VALUE ' - '.

CONCATENATE C1 C2 C3 C4 INTO C5.

WRITE C5.

CONCATENATE C1 C2 C3 C4 INTO C5 SEPARATED BY SEP.

WRITE / C5.

Output:

Summerholiday

Sum - mer - holi - day

In C1 to C5, the trailing blanks are ignored. The separator SEP retains them.

REgards,

Bhaskar

0 Kudos

HI

Please use the following code.

data: W_STR1 type string.

data: W_STR2 type string.

data: W_STR3 type string.

W_STR1 = 'THIS IS'.

W_STR2 = 'A BOOK'.

CONCATENATE W_STR1 W_STR2 INTO W_STR3.

WRITE:/ W_STR3.

Infact some spacing is required between "=".

Regards

Geogy

Please reward usefull answer!!!

Former Member
0 Kudos

Hello,

Change the code like this.


W_STR1='THIS IS'.
W_STR2='A BOOK'.
CONCATENATE W_STR1 W_STR2 INTO W_STR3. " Remove the comma
WRITE:/ W_STR3. 

Vasanth

former_member404244
Active Contributor
0 Kudos

Hi,

remove the comma between W_STR1 and W_STR2.

write like this.

W_STR1='THIS IS'.

W_STR2='A BOOK'.

CONCATENATE W_STR1 W_STR2 INTO W_STR3.

WRITE:/ W_STR3.

Regards,

Nagaraj

Former Member
0 Kudos

u have to declare all the three datas.

data :w_str1(7),w_str2(6),w_str3(14).

W_STR1='THIS IS'.

W_STR2='A BOOK'.

CONCATENATE W_STR1 W_STR2 INTO W_STR3.

WRITE:/ W_STR3.

or

data : w_str1 type string,

w_str2 like w_str1,

w_str3 like w_str1.

W_STR1='THIS IS'.

W_STR2='A BOOK'.

CONCATENATE W_STR1 W_STR2 INTO W_STR3.

WRITE:/ W_STR3.

Former Member
0 Kudos

Hi Rams,

Use this code your problem will clear,

DATA: W_STR1 TYPE STRING,

W_STR2 TYPE STRING,

W_STR3 TYPE STRING.

W_STR1 = 'THIS IS'.

W_STR2 = 'A BOOK'.

CONCATENATE W_STR1 W_STR2 INTO W_STR3.

WRITE:/ W_STR3.

IF USEFULL REWARD

Former Member
0 Kudos

h i rams,

CONCATENATE

Combines a series of strings into a single string.

Syntax

CONCATENATE <c1>... <cn> INTO <c> [ SEPARATED BY <s> ].

The strings <c1> to <cn> are concatenated, and the result placed in <c>. The SEPARATED BY addition allows you to specify a string <s> to be placed between the strings

If useful reward POINTS.

Former Member
0 Kudos

Hi , here is your result

report  zrdez .
data : W_STR1 type  string  value 'THIS IS',
         W_STR2 type  string  value  'A BOOK',
        W_STR3 type  string   .
CONCATENATE W_STR1 W_STR2 INTO W_STR3.
WRITE:/ W_STR3.

O/p

<b>THIS ISA BOOK</b>

reward points if it is usefull ...

Girish

Former Member
0 Kudos

HI,

see this.

data:W_STR1(10),W_STR2(10),W_STR3(20).

W_STR1 = 'THIS IS'.

W_STR2 = 'A BOOK'.

CONCATENATE W_STR1 W_STR2 INTO W_STR3 SEPARATED BY space.

WRITE:/ W_STR3.

rgds,

bharat.

Former Member
0 Kudos

data:

w_str1(10) type c,

w_str2(10) type c,

w_str3(20) type c.

W_STR1='THIS IS'.

W_STR2='A BOOK'.

CONCATENATE W_STR1 W_STR2 INTO W_STR3.

WRITE:/ W_STR3.

Remove comma in your code.

This works.

Regards,

Pavan P.