Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

abap

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.
like image 528
Eduardo Copat Avatar asked Sep 17 '13 21:09

Eduardo Copat


People also ask

What is the most efficient way to concatenate many strings together?

If you are concatenating a list of strings, then the preferred way is to use join() as it accepts a list of strings and concatenates them and is most readable in this case. If you are looking for performance, append/join is marginally faster there if you are using extremely long strings.

What is the correct way to concatenate the strings?

Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs.

How do I concatenate two characters to a string?

The strcat() method is used to concatenate strings in C++. The strcat() function takes char array as input and then concatenates the input values passed to the function. In the above example, we have declared two char arrays mainly str1 and str2 of size 100 characters.


2 Answers

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
like image 184
oldwired Avatar answered Nov 09 '22 21:11

oldwired


Yes, you can use String Templates, which were introduced in ABAP 7.02.

An example following:

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

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

  foobar = |{ foo } and { bar }|.
like image 37
Eduardo Copat Avatar answered Nov 09 '22 23:11

Eduardo Copat