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: 

How to retain spaces in a string...really urgent

Former Member
0 Kudos
1,763

Hi all,

I need to concatenate spaces after a string. Ho9w do i do that?

For example...

Data : s type string.

s = 'ABC'.

I need to add '40 BLANK SPACES' after the string ABC.

please revert back as soon as possible?

Thanks a million in advance for the help.

Regards,

Pritts.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
391

Hi,

Simply you can have a char array of size 40 as

data: c1(40) type c.

c1 = 'ABC'.

Regards,

Uma

13 REPLIES 13

Former Member
0 Kudos
391

SAP ABAP interprets SPACE as the END of string. Hence you cannot do like that.

If you want to append two strings with blanks in middle you can use this.

DATA c1(10) VALUE 'ABC'.
DATA c2(10) VALUE 'XYZ'.
DATA sep(10) VALUE '      '.
DATA c3(50).

CONCATENATE c1 c2 INTO c3 SEPARATED BY sep.

0 Kudos
391

Hi Wenceslaus,

I appreciate yr quick response.

My requirement is different. I dont want to concatenate two strings, rather i want to append some sapces after the string.

Just a brief introduction to m y scenario..i am working on a proxy to file scenario in XI wherein the abap program will pass the data to XI and XI will upload the field in XI application server.

I want to append spaces at the end of the string and pass it to Xi.

So all the work needs to be done in ABAP.

Waiting for yr reply..thank you very much.

Regards,

Pritts

0 Kudos
391

Then you can use the method suggested by Satesh.

0 Kudos
391

hi,

my code works well...

Former Member
0 Kudos
391

Hi,

this code works well. you can vary the value of count and accordingly the size of the string varies...

data : str type string value ' abc' , count type i value 40.

while count ne 0.

concatenate str '*' into str separated by space.

count = count - 1.

endwhile.

replace all occurrences of '*' in str with space.

write : str.

write : str.

reward points if helpful

0 Kudos
391

Hi Satesh,

Thanks it worked....but can i have some simpler solution.

Its a very helpful answer but in my scenario there can be some performance issue due to this.

Thanks...I have awarded u the points for this...

Regards,

Pritts

0 Kudos
391

This would be the simplest solution without performance overhead. Note the ` (character to the left of 1 in your keyboard.

DATA c1 TYPE STRING VALUE `ABC`.
DATA c2 TYPE string VALUE `                     `.
CONCATENATE c1 c2 INTO c1.
WRITE c1.
WRITE 'Hi'.

0 Kudos
391

Hi Wenceslaus,

Yeah it worked..... i have awarded the points for the same.

Thanks....but there are scenarios wherein i have appedn 73 blank spaces.....any help???

Regards,

Pritts

athavanraja
Active Contributor
0 Kudos
391
in the string just use ` instead of ' .

s = `ABC                                                `.

Regards

Raja

0 Kudos
391

Hi Durairaj,

Thanks for the help.

But i have cases wherein i have to add approximately 76 spaces after the string.

Wont that be hell lot of work???

Anyways thanks for the help.

Former Member
0 Kudos
392

Hi,

Simply you can have a char array of size 40 as

data: c1(40) type c.

c1 = 'ABC'.

Regards,

Uma

0 Kudos
391

HI Uma,

I tried yr solution.

yeah it worked.....Thanks a lot...Problem solved

I have awarded u points...

Thank u all for yr valuable time

Regards,

Pritts.

Former Member
0 Kudos
391

Do like this.

DATA c1 TYPE STRING VALUE `ABC`.
DATA c20 TYPE string VALUE `                    `.
DATA c13 TYPE string VALUE `             `.
CONCATENATE c1 c20 c20 c20 c13 INTO c1.
WRITE c1.
WRITE 'Hi'.