CONCATENATE
Short Reference
ABAP Syntax CONCATENATE {dobj1 dobj2 ...}|{LINES OF itab}
INTO result
[IN {CHARACTER|BYTE} MODE]
[SEPARATED BY sep]
[RESPECTING BLANKS].
ABAP_ADDITIONS:
1 ... IN {CHARACTER|BYTE} MODE
2 ... SEPARATED BY sep
3 ... RESPECTING BLANKS
What does it do? Concatenates either the content of the data objects
dobj1, dobj2, ... of the rows of the internal table itab in
accordance with their order and assigns them to the target field
result . itab is a
functional operand position . The following can be specified for the
target field result :
An existing variable to which the result of the chaining can be
converted.
An inline declaration with DATA(var) .
If IN CHARACTER MODE is used, the declared variable is of the
type string ; if IN BYTE MODE is used, it is of the type
xstring .
If the target field result has a fixed length and this is
greater than the length required, the field is filled on the right with
blanks or hexadecimal 0. If the target field is too short, the
concatenation is truncated on the right. If the target field is a
string, its length is adjusted accordingly.
When character strings are processed, trailing blanks are usually
ignored for data objects dobj1, dobj2 ... or rows in the internal
table itab of fixed length.
System Fields
sy-subrc Meaning
0The content of all data objects dobj1, dobj2 ... or itab
rows was passed to the target field result .
4The content of the data objects dobj1, dobj2 ... or itab
rows could not be passed completely, since result is too
short.
Latest notes: Instead of CONCATENATE , it is usually also possible
to use string expressions for elementary
fields. These expressions enable concatenations using either
concatenation operators
or embedded
expressions in string templates . To
concatenate rows in an internal table, the predefined function
concat_lines_of can be used.
The ABAP runtime environment executes an internal optimization to
reduce reallocations if new fragments are attached to an existing
string within a loop.
ABAP_ADDITION_1 ... IN {CHARACTER|BYTE} MODE
What does it do? The optional IN {CHARACTER|BYTE} MODE addition
determines whether character
string or byte string processing is carried out. If the addition is
not specified, character string processing is carried out. Depending on
the processing type, the data objects dobj1, dobj2 ... , the rows
of the internal table itab , and the separator sep must be
character-like or
byte-like .
ABAP_ADDITION_2 ... SEPARATED BY sep
What does it do? The addition SEPARATED BY is used to insert the
content of data object sep between the content of the consecutive
data objects dobj1, dobj2 ... . When strings are processed,
trailing blanks are respected in separators sep of fixed length.
Example ABAP Coding After the first CONCATENATE statement, result
contains "Wehaveallthetimeintheworld", while after the second it
contains "We have all the time in the world" .
DATA: t1 TYPE c LENGTH 10 VALUE 'We',
t2 TYPE c LENGTH 10 VALUE 'have',
t3 TYPE c LENGTH 10 VALUE 'all',
t4 TYPE c LENGTH 10 VALUE 'the',
t5 TYPE c LENGTH 10 VALUE 'time',
t6 TYPE c LENGTH 10 VALUE 'in',
t7 TYPE c LENGTH 10 VALUE 'the',
t8 TYPE c LENGTH 10 VALUE 'world'.
CONCATENATE t1 t2 t3 t4 t5 t6 t7 t8
INTO DATA(result).
...
CONCATENATE t1 t2 t3 t4 t5 t6 t7 t8
INTO result SEPARATED BY space.
ABAP_ADDITION_3 ... RESPECTING BLANKS
What does it do? The addition RESPECTING BLANKS is only allowed
when strings are processed and respects the trailing blanks for data
objects dobj1, dobj2 ... or rows in the internal table itab
. If this addition is not used, the blanks are respected for data
type string only.
Latest notes: If the addition RESPECTING BLANKS is specified, the
statement CONCATENATE can be used to assign any character strings
text to target fields str of type string while
respecting trailing blanks: CLEAR str. CONCATENATE str text
INTO str RESPECTING BLANKS.
Example ABAP Coding After the first CONCATENATE statement, result
contains "When_the_music_is_over", and after the second it contains
"When______the_______music_____is________ over______". The underscores
here represent blanks.
TYPES text TYPE c LENGTH 10.
DATA itab TYPE TABLE OF text.
APPEND 'When' TO itab.
APPEND 'the' TO itab.
APPEND 'music' TO itab.
APPEND 'is' TO itab.
APPEND 'over' TO itab.
CONCATENATE LINES OF itab INTO DATA(result) SEPARATED BY space.
...
CONCATENATE LINES OF itab INTO result RESPECTING BLANKS.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved