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.
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.
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.
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.
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
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 }|.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With