SPLIT

Variants:

1. SPLIT f AT g INTO h1 ... hn.

2. SPLIT f AT g INTO TABLE itab.

Depending on whether byte or character string processing is carried out, the operands can only be byte-type or character-type (see Overview).

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Only character fields allowed in string processing.

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Character String Processing and Unicode.

Variant 1

SPLIT f AT g INTO h1 ... hn.


Extras:

1. ... IN BYTE MODE

2. ... IN CHARACTER MODE

Effect

Splits f wherever the separator g occurs and places the resulting sections into the fields h1 ... hn (n >= 2). Note that if g has type C, the field is used in its defined and not its occupied length.
The field is split using the following procedure: f is split internally into a set of target fields k1 to kn with the same type as f. These are then transferred into the actual target fields h1 to hn using MOVE semantics.

The Return Code is set as follows:

SY-SUBRC = 0:
All of the fields hi (1 <= i <= n) were large enough.
SY-SUBRC = 4:
One of the fields hi was not large enough and significant characters were lost.

Examples

DATA: NAMES(30)    TYPE C VALUE 'Charly, John , Peter',
      NAMES2       TYPE STRING,
      ONE(10)      TYPE C,
      TWO(10)      TYPE C,
      THREE        TYPE STRING,
      FOUR(4)      TYPE C VALUE 'FOUR',
      DELIMITER(2) VALUE ','.

SPLIT NAMES AT DELIMITER INTO ONE TWO.
*     ONE contains 'Charly' and TWO contains 'John , Pet'.
*     SY-SUBRC is 4, because TWO was not large enough to
*     accommodate the whole of the remaining string
SPLIT NAMES AT ',' INTO ONE TWO THREE.
*     ONE contains 'Charly', TWO contains ' John',
*     THREE contains ' Peter'.
SPLIT NAMES AT ', ' INTO ONE THREE TWO.
*     ONE contains 'Charly', THREE contains 'John',
*     TWO contains 'Peter'.
CONCATENATE NAMES '' INTO NAMES2 SEPARATED BY SPACE.
SPLIT NAMES2 AT DELIMITER INTO ONE TWO THREE FOUR.
*     ONE contains 'Charly', TWO contains 'John',
*     THREE contains 'Peter ', FOUR is empty.
SPLIT NAMES2 AT DELIMITER INTO ONE FOUR THREE.
*     ONE contains 'Charly', FOUR contains 'John',
*     THREE contains 'Peter', SY-SUBRC is 4, since
*     FOUR was not large enough (spaces are significant
*     characters!)

Addition 1

... IN BYTE MODE

Effect

If you use this addition, all fields must be of the type X or XSTRING.

Addition 2

... IN CHARACTER MODE

Effect

This addition is optional and corresponds to the default setting (see above).

Notes

Variant 2

SPLIT f AT g INTO TABLE itab.


Extras:

As with variant 1

Effect

Similar to variant 1
The sections of f are placed in the internal table itab. The sytsem creates a table row for each section of f.
Note: If f ends with the separator string g, the system does not create an empty table row at the end. This is in contrast to what happens when g occurs at the beginning of f.

Example

TYPES: BEGIN OF ITAB_TYPE,
        WORD(20),
      END   OF ITAB_TYPE.

DATA: ITAB TYPE STANDARD TABLE OF ITAB_TYPE WITH
                NON-UNIQUE DEFAULT KEY INITIAL SIZE 5.

SPLIT 'STOP Two STOP Three STOP   ' AT 'STOP' INTO TABLE ITAB.

ITAB now has three rows. The first is empty, the second contains ' Two', and the third ' Three'.

Note

Performance:

The runtime required for the SPLIT statement in the first example of variant 1 is approximately 15 msn (standard microseconds). If you write the sections of f into an internal table, the runtime is around 30 msn.

Related

CONCATENATE, FIND, SEARCH, SHIFT

Additional help

Splitting Strings