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

hello friends,

i was trying to concatenaete two values with space in between,

but its not giving space in the output file.

concatenate var1 ' ' var2 into result.

but its outputting var1var2 continously with out that gap.

can some one help.

15 REPLIES 15

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Try this.

concatenate var1 var2 into result separated by space.

Regards,

RIch Heilman

Former Member
0 Kudos

concatenate var1 ' ' var2 into result separted by space.

Former Member
0 Kudos

but friends,

if my case

i have to display

v1 v2 v3 v4

if v3 doesnot have value, it should show space.

like

v1 v2 ' ' v4.

0 Kudos

HI saritha

U can use the following statement

CONCATENATE V1 V2 V3 V4 into V5 separated by space.

Reward points me if its useful.

Regards

ravi

0 Kudos

i think you will get one space for variable to variable.

0 Kudos

Hi Saritha,

I think this is not possible.

It concatenates all the variables and puts one space in between all of them.

It will ignore v3 if it has no value or value ' '.

Earlier i had to get 2 spaces in between 2 variables in a concatenate statement but i couldn't.

I had to do it using +offset(length) method.

0 Kudos

Hi Saritha,

Now let me give solution for your situation.

You say you have 3 variable v1 v2 v3 and you want to cancatnate into v4. If any of the variable is empty you want to display space.

Ex:

DATA : v1(3) value 'one',

v2(3),

v3(3) value 'two',

v4(15).

IF v1 IS INITIAL.

v1 = '#'.

ENDIF.

IF v2 IS INITIAL.

v2 = '#'.

ENDIF.

IF v3 IS INITIAL.

v3 = '#'.

ENDIF.

CONCATENATE v1 v2 v3 into v4.

REPLACE '#' with SPACE into v4.

WRITE v4.

Output Here is 'ONE TWO'

I guess this solves your problem.

Reward points to all useful answers.

Regards,

SaiRam

Former Member
0 Kudos

why dont u try this one

concatenate var1 var2 into result separated by space.

Former Member
0 Kudos

Hi Saritha

When you concatenate without separating the strings by space then it doesnt take into account the spaces in the strings being concatenated.

Only by the addition of 'SEPARATED BY space' can you take care of the variables with a value of space in them.

So go ahead with

CONCATENATE var1 ' ' var2 into result SEPARATED BY space.

Cheers

Shivika

Former Member
0 Kudos

hey darshil

if the value in v2 is space and u use the concatenate with separated by space , it can never ignore that space in v2. instead it will introduce 2 spaces in between v1 and v3. code and check.

cheers

shivika

Message was edited by:

Shivika Bhorchi

0 Kudos

Hi Shivika,

you can write the code and check.

data : v1(10), v2(10), v3(10), v4(40).

v1 = 'hi'.

v2 = ' '.

v3 = 'abac.'.

concatenate v1 v2 v3 into v4 separated by space.

write v4.

those 2 spaces are : one space after v1 and one space before v3.

v2's spaces will never be displayed.

you can try having value of v2 as 'a '.

it will still display 'hi a abac.' and it will ignore spaces fo variable v2.

Former Member
0 Kudos

try this one this is working

concatenate var1 var2 var3 var4 into result separated by space.

if there is nthng in variable thn it will be displayed as a space.

eg var1='one', var2 = 'two', var4= 'four'.

thn o/p = one two four.

after two there will be 2 spaces.

does this works ?

Former Member
0 Kudos

Hi darshil

I guess you are right. Sai's solution is working perfectly in this case.

S0025444845
Active Participant
0 Kudos

Hi,

Try this just copy n paste the code n run.

DATA: var1(6) TYPE c VALUE 'ABCDEF',

var2(5) TYPE c VALUE 'GHIJK',

result(12) TYPE c .

CONCATENATE var1 var2 INTO result SEPARATED BY ' '.

WRITE: result.

with regards,

Sudha.

reward points if useful.

Former Member
0 Kudos

you can use the folloing code to do the formating of the data .

CONCATENATE l_str_tmp(4) '-' l_str_tmp4(2) '-' l_str_tmp6(2) INTO l_str_date .

CONCATENATE l_str_tmp8(2) ':' l_str_tmp10(2) ':' l_str_tmp+12(2) INTO l_str_time.

CONCATENATE l_str_date l_str_time INTO l_str_tmp SEPARATED BY space .