How to used the utility SPLIT statement? Explain with an example.
Splitting Character Strings: To split a character string into
two or more smaller strings, use the SPLIT statement as follows:
SPLIT c AT del INTO c1 ... cn.
The system searches the field c for the separator del. The parts before
and after the separator are placed in the target fields c1 ... cn.
To place all fragments in different target fields, you must specify
enough target fields. Otherwise, the last target field is filled with the
rest of the field c and still contains delimiters.
If all target fields are long enough and no fragment has to be truncated,
sy-subrc is set to 0. Otherwise it is set to 4.
DATA: string(60) TYPE c,
p1(20) TYPE c VALUE ,
p2(20) TYPE c VALUE ,
p3(20) TYPE c VALUE ,
p4(20) TYPE c VALUE ,
del(3) TYPE c VALUE .
string = ' Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5'.
WRITE string.
SPLIT string AT del INTO p1 p2 p3 p4.
WRITE / p1.
WRITE / p2.
WRITE / p3.
WRITE / p4.
The output appears as follows:
Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5
Part 1
Part 2
Part 3
Part 4 *** Part 5
Note that the contents of the fields p1 ...p4 are totally overwritten
and that they are filled out with trailing blanks.
You can also split a string into the individual lines of an internal
table as follows:
SPLIT c AT del INTO TABLE itab.
Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP MM SD Consultant
Contact : serkurumsal@yandex.com
Social Plugin