What is the utility of SPLIT statement

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.

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.