Skip to Content

How to add multiple spaces to the middle of a string?

Hi,

I have two strings:

str1 = 'NAME'

str2 = 'ADDRESS'

I want to create a third string:

str3 = 'NAME ADDRESS'

These do not work:

1) str3 = str1 + ' ' + str2

2) concatenate str1 ' ' str2 into str3

3) concatenate str1 ' ' str2 into str3 separated by space

4) str3 = 'NAME&ADDRESS'

replace '&' in str3 with ' '

5) str3 = 'NAME&ADDRESS'

overlay str3 with ' ' only '&'

Any other ideas?

Thx.

Andy

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2008 at 02:52 PM

    Use STRLEN to determine the length of NAME and then put ADDRESS as many spaces over as needed.

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2008 at 02:50 PM

    Use the respecting blanks addtition:

    concatenate ................RESPECTING BLANKS.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2008 at 02:52 PM

    Hi,

    i do this and it works:

    DATA: STR0 TYPE STRING VALUE 'Vorname'.

    DATA: STR1 TYPE STRING VALUE 'Nachname'.

    DATA: STR2 TYPE STRING.

    *

    CONCATENATE STR0 STR1 INTO STR2 SEPARATED BY SPACE.

    *

    WRITE: / STR0.

    WRITE: / STR1.

    WRITE: / STR2.

    Any problem with my example?.

    regards, Dieter

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2008 at 02:52 PM

    hi,

    You can Try

    Concatenate Var1 space Var2 into var3.

    Regards

    Sumit Agarwal

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 11, 2008 at 02:53 PM

    hi Andrew,

    how many spaces do you want? what is not working?

    valid examples:

    CONCATENATE str1 str2 INTO str3 SEPARATED by space.

    ==> result will be 1 space between the two words

    CONCATENATE str1 ' ' str2 INTO str3 SEPARATED by space RESPECTING BLANKS.

    ==> result will be 2 spacea between the two words, but this is 6.0 syntax!

    +you can also use offset.

    hope this helps

    ec

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 11, 2008 at 02:54 PM

    Hi,

    check this...

    concatenate str1 ' ' str2 into str3 separated by space

    concatenate str1 str2 into str3 separated by space

    regards

    padma

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 11, 2008 at 02:54 PM

    >

    > str1 = 'NAME'

    > str2 = 'ADDRESS'

    > Any other ideas?

    >

    > Thx.

    > Andy

    These are not strings, strings are enclosed in ` and not in apostrophes like '.

    so use this:

      concatenate str1 str2 into str3 in character mode separated by space.
    

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 28, 2016 at 04:10 PM

    My requirement was to add 5 spaces in betwwen 2 strings and i wrote below code and it worked for me,

    REPORT ztestttt.

    DATA : kunnr TYPE kunnr,

    vkorg TYPE vkorg,

    text TYPE string.

    DATA : lc(5) TYPE c VALUE ' '.

    kunnr = 'W8400'.

    vkorg = '2500'.

    CONCATENATE kunnr vkorg INTO text SEPARATED BY lc.

    WRITE : text.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.