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

SPLIT  Syntax Diagram

Short Reference

Syntax

SPLIT dobj AT sep INTO
      { {result1 result2 ...} | {TABLE result_tab} }
      [IN {CHARACTER|BYTE} MODE].

Addition:


... IN {CHARACTER|BYTE} MODE


Effect

The content of the operand dobj is separated into segments in accordance with the sequence of separators in sep. The results are either stored in individual target fields result1 result2 ... or in the rows of an internal table result_tab.

At least two target fields result1 result2 ... must be specified. dobj and sep are character-like expression positions.

The system searches the operand dobj from left to right for all occurrences of the content of the operand sep. The search is case-sensitive. All segments from the start of the operand to the first occurrence, between the occurrences, and from the last occurrence to the end of the operand are assigned one by one to the individual target fields result1 result2 ..., or appended to the internal table result_tab.

If the content of the operand sep is found immediately at the start of dobj, or occurs in direct succession in dobj, the result of the separation is an empty string. If the content of sep is at the end of dobj, the search is terminated and no further separation takes place to the right of this point.

If the content of the operand sep is not found or is an empty string, the result of the split is a single segment that contains the whole content of dobj, and which is assigned to the first individual target field or the first row of the internal table.

In character string processing, the trailing blanks are respected for separators sep of fixed length, but not in the operand dobj or in the segments produced by the separation.

System Fields

sy-subrc Meaning
0 The segments were passed to the target fields or the internal table without being truncated.
4 At least one of the segments was truncated on the right when being passed to the target fields or internal table.

Notes

Addition

... 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 type of processing, the operands dobj, sep, and the target fields result1 result2 ... or the rows of the internal table result_tab must be byte-like or character-like.

Example

The text field text is separated at its blanks, firstly into the three strings str1, str2, and str3, and then into an internal table with the row type string. Since the three strings are not enough for all seven parts, str3 contains "drag it is getting old" after the separation, while the internal table contains seven rows; one for each word in text.

DATA text TYPE string.

text = `What a drag it is getting old`.

SPLIT text AT space INTO: DATA(str1) DATA(str2) DATA(str3),
                          TABLE DATA(itab).