Search code examples
abap

Is there another way to concatenate instead of using the CONCATENATE keyword?


Is there another way to concatenate in ABAP instead of using the CONCATENATE keyword?

An example using CONCATENATE:

DATA:
  foo    TYPE string,
  bar    TYPE string,
  foobar TYPE string.

  foo = 'foo'.
  bar = 'bar'.

  CONCATENATE foo 'and' bar INTO foobar SEPARATED BY space.

Solution

  • You can (starting with ABAP 7.02) use && to concatenate two strings.

    Data:
    foo    TYPE string,
    bar    TYPE string,
    foobar TYPE string.
    
    foo = 'foo'.
    bar = 'bar'.
    
    foobar = foo && bar.
    

    This also works with character literals:

    foobar = 'foo' && 'bar'.
    

    For preserving spaces, use this kind of character literal named "text string literal" which is defined with two grave accents (U+0060):

    foobar = foo && ` and ` && bar