Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Statements for Character String and Byte String Processing 

CONCATENATE

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CONCATENATE {dobj1 dobj2 ...}|{LINES OF itab} 
            INTO result
            [IN {CHARACTER|BYTE} MODE]
            [SEPARATED BY sep]
            [RESPECTING BLANKS].

Extras

1. ... IN {CHARACTER|BYTE} MODE

2. ... SEPARATED BY sep

3. ... RESPECTING BLANKS

Effect

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
0 The content of all data objects dobj1, dobj2 ... or itab rows was passed to the target field result.
4 The content of the data objects dobj1, dobj2 ... or itab rows could not be passed completely, since result is too short.


Notes

Addition 1

... IN {CHARACTER|BYTE} MODE

Effect

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.

Addition 2

... SEPARATED BY sep

Effect

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

After the first CONCATENATE statement, the 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. 

Addition 3

... RESPECTING BLANKS

Effect

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.


Note

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

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.