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.
SPLIT f AT g INTO h1 ... hn.
1. ... IN
BYTE MODE
2. ... IN CHARACTER MODE
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:
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!)
... IN BYTE MODE
If you use this addition, all fields must be of the type X or XSTRING.
... IN CHARACTER MODE
This addition is optional and corresponds to the default setting (see above).
SPLIT f AT g INTO TABLE itab.
As with variant 1
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.
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'.
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.
CONCATENATE, FIND, SEARCH, SHIFT
Splitting Strings