"
Supported by

Let’s concatenate

We start with two variables:


DATA word1 TYPE string.
DATA word2 TYPE string.
DATA: phrase TYPE string.

word1 = ‘this’.
word2 = ‘that’.

And we want to concatenate them adding the word “plus” between them and, of course, separate them by space.

Form 1 (the classic):


CONCATENATE word1 ‘plus’ word2 INTO phrase SEPARATED BY space.

Form 2, which doesn’t leave a space between them:


phrase = word1 && ‘ ‘ && 'plus' && ‘ ‘ && word2.

Form 3, more far fetched but which separates the words:


phrase = word1 && ‘ALT+255‘ && 'plus' && ‘ALT+255‘ && word2.

(in which ALT+255 is really pressing ALT and then writing 255)
(it isn’t really a space but it looks the same)

Forma 4, the state of the art in concatenation:


phrase = | { word1 } plus { word2 } |.

Actually, this last one even lets you invoke methods directly:


phrase = | { o_book->get_word( 1 ) } plus { o_book->get_word( 2 ) } |.

Thank you Ricardo Monteiro for the ALT+255 trick and Sérgio Fraga for showing us the future.
Thank you halfrain for the photo.

Greetings from Abapinho.

5 comentários a “Let’s concatenate”

  1. Tommas Diz:

    Hi,
    phrase = word1 && ‘ ‘ && word2.
    phrase = word1 && ` ` && word2. “this will keep space

    For more info:
    http://help.sap.com/abapdocu_731/en/abenstring_templates.htm

  2. Tommas Diz:

    Single quotation mark should be different, but they are “parsed”/changed to other in this web. Check example in link (different kinds of quotation marks).

  3. Tommas Diz:

    One more comment :D

    Here I found direct help page about what I wanted to say:
    http://help.sap.com/abapdocu_731/en/abenliteral.htm

    The thing is, that “Text string literals”(check link) keeps space. So by using them, modified example “Form 2” would work.

  4. Nuno Godinho Diz:

    Hi Thommas, indeed you’re right. I’ll soon update the article to reflect your findings.

  5. Nuno Godinho Diz:

    Thank you very much!

Deixe um comentário


About Abapinho
Abapinho runs on WordPress
Articles (RSS) e Comments (RSS).