SPLIT is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.
1. SPLIT f AT g INTO h1 … hn.
2. SPLIT f AT g INTO TABLE itab.
SPLIT f AT g INTO h1 … hn.
Splits the contents of the f according to the delimiter g and places them in the fields h1 to hn ( n >= 2).
g is used in its defined length.
The return code value is set as follows:
SY-SUBRC = 0 All hi fields (1 <= i <= n ) were big enough.
SY_SUBRC = 4 One of the hi fields was not big enough and had to be truncated.
DATA: NAMES(30) VALUE ‘Charly, John, Peter’,
DELIMITER(2) VALUE ‘,’.
SPLIT NAMES AT DELIMITER INTO ONE TWO.
Now, ONE has the value “Charly” and TWO has the value “John, Pete” .
SY-SUBRC is set to 4, since TWO was not big enough to include “John, Peter” .
DATA: NAMES2(30) VALUE ‘Charly, John, Peter’,
THREE(10) VALUE ‘New York’,
SIX(10) VALUE ‘SAP’.
SPLIT NAMES2 AT ‘,’ INTO THREE FOUR FIVE SIX.
IF THREE = ‘Charly’ AND
FOUR = ‘ John’ AND
FIVE = ‘ Peter’ AND
SIX = SPACE.
WRITE ‘SPLIT is OK’.
Outputs “SPLIT is OK” .
the number of target fields is greater than the number of delimiters in
the source field, very little information ought to be lost. Therefore,
the last target field in this case contains the “rest”, including the
delimiters (see first example).
If the source field does not contain the separator sequence at all, it is copied incomplete to the first target field.
SPLIT f AT g INTO TABLE itab.
Like variant 1.
Stores the components of f in the internal table itab . For each part of f , a “special” table line is created.
f is considered without trailing blanks.
DATA: BEGIN OF ITAB OCCURS 10,
END OF ITAB.
SPLIT ‘STOP Two STOP Three STOP ‘ AT ‘STOP’ INTO TABLE ITAB.
Now, ITAB has three lines. The first line is blank, the second contains ‘Two’ and the third contains ‘Three’ .
runtime required for the SPLIT command in the first example for variant
1 is about 15 msn (standardized microseconds). If the sub-fields of f
are written to an internal table, about 30 msn are needed.
[ FREE ] SUBSCRIBE
RECEIVE UPDATES & SAP ARTICLES RIGHT IN YOUR INBOX.