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

Concatenate string problem

former_member220801
Participant
0 Likes
1,279

How can I concatenate two string, but yet preserved the space at the back?

e.g.

DATA: A1 TYPE STRING,

A2 TYPE STRING.

A1 = 'AA '

A2 = 'BB '

If I use

CONCATENATE A1 A2 TO A2

it gives 'AABB'.

How can I concatenate the string and get 'AA BB '?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,255

DATA: A1 TYPE STRING,

A2 TYPE STRING.

A1 = 'AA '.

A2 = 'BB '.

CONCATENATE A1 A2 ' ' inTO A2 "add 2 blanks in quotes

separated by space.

write: / a2.

Reward points accordingly.

12 REPLIES 12
Read only

Former Member
0 Likes
1,255

CONCATENATE a1 a2 INTO a2 SEPARATED BY space. This will put a space between the two.

Rob

Read only

Former Member
0 Likes
1,256

DATA: A1 TYPE STRING,

A2 TYPE STRING.

A1 = 'AA '.

A2 = 'BB '.

CONCATENATE A1 A2 ' ' inTO A2 "add 2 blanks in quotes

separated by space.

write: / a2.

Reward points accordingly.

Read only

0 Likes
1,255

Sorry.. the content has been somehow modified after posting to the forum.

A1 = 'AA' followed by 4 space

A2 = 'BB' followed by 2 space

The desired output should be

AA + 4 space + BB + 2 space.

Thanks!

Read only

0 Likes
1,255

Why do you need spaces at the end?

Rob

Read only

0 Likes
1,255

From F1 (4.6C) on 'STRING':


Working with Strings 
In the current release it has not been possible to fully 
complete the implementation of strings. Especially the  
handling of blank characters at the end of a string has  
not been finalized for a number of ABAP statements. 

For the highlighted argument positions of the following  
ABAP statements, blank characters at the end of strings  
are not taken into account. This may change in the next  
release. Therefore strings with blank characters at the  
end should not be used in these positions.

Rob

Read only

0 Likes
1,255

I am using 4.7 Ext 200.

So space char at the back is always truncated using string functions? Is It?

Thanks!

Read only

0 Likes
1,255

So I think you are stuck with someting like:


REPORT ztest LINE-SIZE 80 LINE-COUNT 64 MESSAGE-ID zc.
DATA: a1 TYPE string,
      a2 TYPE string,
      a3 TYPE string.

a1 = 'AA '.
a2 = 'BB '.
a3 = '****'.

CONCATENATE a1 a3 a2 INTO a2.

DO 4 TIMES.
  REPLACE '*' WITH space INTO a2.
ENDDO.

WRITE /001 a2.

Rob

Read only

0 Likes
1,255

Hi,

try the following..


data: a1 type string,
a2 type string,
a3(3) value '   ',
a4(1) value ' '.
a1 = 'AA'.
a2 = 'BB'.
concatenate a1 space into a1 separated by a3.
concatenate a2 space into a2 separated by a4.
a3 = '123'.
write:/ a1,a2,a3.

I put the third variable just see whether there are two spaces after BB.

Regards,

Suresh Datti

Read only

0 Likes
1,255

In 4.6C, yes. You should do F1 yourself on 'STRING' in your 4.7 ssytem and see what turns up. Maybe there's a workaround.

Rob

Read only

0 Likes
1,255

Seeing your diff req, use this:

Re: Concatenate string problem

Posted: Jan 9, 2006 8:06 PM Reply E-mail this post

DATA: A1 TYPE STRING,

A2 TYPE STRING.

data: Filler4(4) value ' '. " four blanks

data: Filler2(2) value ' '. two blanks

A1 = 'AA '.

A2 = 'BB '.

CONCATENATE A1 Filler4 A2 Filler2 inTO A2 separated by space.

Read only

0 Likes
1,255

Thanks for your reply.

But how can it handle if the no. of space char is different each time?

four space followed by AA is only just an example... it varies case by case in my situation.

Thanks!

Read only

0 Likes
1,255

Hi u can try this one

data: a1 type string,

a2 type string,

a3(1) value ' '.

a1 = 'AA'.

a2 = 'BB'.

concatenate a1 a3 a3 a3 a3 a3 a2 a3 a3 into a1 .

write:/ a1.

This will do for ur scenario.

<i>>But how can it handle if the no. of space char is different each time?

>four space followed by AA is only just an example... it varies case by case in my situation.</i>