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: 

Concatenating variables

Former Member
0 Kudos
179

Hi sap gurus. I was just wondering if it is possible to concatenate two variables without SAP changing the total length. For example, if I have two variables declared as:

DATA: temp1(10) type c,
      temp2(10) type c.

temp1 = 'hello'.
temp2 = 'jerry'.

if we use:

concatenate temp1 temp2 into temp3.

The result in temp3 would be "hellojerry".

Is there a way for me to concatenate this variables with the result in temp3 as "hello jerry " since the maximum allocated space for both variables is 10.

9 REPLIES 9

Former Member
0 Kudos
149

Hi

concatenate temp1 temp2 into temp3 separated by space.

Anyway depend on length of temp3, it should be long 20 chars.

Max

Message was edited by: max bianchi

Former Member
0 Kudos
149

separated.......

Message was edited by: Surpreet Singh Bal

Former Member
0 Kudos
149

Use --

concatenate temp1 temp2 into temp3 separated by space.

Cheers.

Former Member
0 Kudos
149

Hi,

DATA: temp1(10) type c,

temp2(10) type c,

temp3(11).

temp1 = 'hello'.

temp2 = 'jerry'.

concatenate temp1 temp2 into temp3 separated by space.

Svetlin

guillaume-hrc
Active Contributor
0 Kudos
149

The length of variables <i>temp1</i> and <i>temp2</i> is not relevant here. But you should give <i>temp3</i> a sufficient length : 10 would be sufficient in your example.

Please, note also that there won't be any space at the end of 'hello jerry ' (you write a trailing space in your example). The only space added is between <i>temp1</i> and <i>temp2</i>.

You could declare <i>temp3</i> on 11 characters in that particular case.

Former Member
0 Kudos
149

hi

the simple way is to use concatenate statement with seprated by space.and for more calrity u use f1 help on concatenate.

if this has solved ur prblm plz gave rewards

thanks

athavanraja
Active Contributor
0 Kudos
149

if you really want to have the white spaced preserved,

use the following

concatenate `hello ` `jerry. ` into temp3 .

please note that i have not used single quote.

Regards

Raja

Former Member
0 Kudos
149

hey catabs. it's raymond from xavier. Where are you now? Anyway, email me at friedpapaya@hotmail.com

Former Member
0 Kudos
149

Hi Ferdinand,

I can understand your query.

<b>Your Problem:</b>

You are having a 3 strings 'temp1', 'temp2' and 'temp3'.

'temp1' & 'temp2' are of length 10 and 'temp3' is of length 20.

In 'temp1' and 'temp2' you are having strings of 5 charecters and remaining 5 charecters are empty.

You are asking whether can we join the 2 strings (temp1,temp2) into a string(result).

So that you should have the 5 charecters which are empty also should be in the 'temp3' string.

<b>Solution:</b>

When you concatenate 2 strings it will removes the unassigned charecters from the source strings starting from the end of string.

If you want to display the spaces also then you have to assign the spaces to the string during initialization.


DATA: temp1(10) type c,
      temp2(10) type c,
      temp3(20) type c.
temp1 = 'hello     '.
             *12345 - blank spaces added in both strings 
temp2 = 'jerry     '.
              
concatenate temp1 temp2 into temp3.

* Here you assign blanks to the string.
* Now it will display 'hello     jerry     '
*                          12345     12345

If you decrease the length of temp3 as 10 it will display only the 'hello ' remaining is ignored.

Hope it helps.

Regards,

Maheswaran.B