A character string can be split into 2 or more smaller strings. This is done using the SPLIT statement. The syntax for the same is shown below.
SPLIT <filed1> AT <separator> INTO <f1> ... <fn>.
Once the above statement is executed the system makes a search for the filed <field1> for the separator <separator> and the contents of <field1> are split at the separator that means the part before the separator is placed in <f1> and after the <separator> is placed in <f2> till <fn>. Application:
This can be very well used while uploading a file separated by commas and placing content separated by commas into different fields.
Also note that to place the fragments into target fields the should be enough target fields to accommodate all the content. In case the contents are more then the last defined filed will contain the remaining values along with the <separator> ie the delimiter.
In case the split is carried out in such a way that all the contents of the string are placed in different fields then Sy-subrc is set to 0. Else sy-subrc is set to 4.
DATA: TESTSPLIT(40), f1(10) VALUE '**********', f2(10) VALUE '**********', f3(10) VALUE '**********', f4(10) VALUE '**********', f5(10) VALUE '**********', f6(10) VALUE '**********', DEL(2) VALUE '!!'.
Always use Pretty Printer and Extended Program Check before releasing the code.
Do not leave unused code in the program. Comment the code thoroughly. Align the comments and the Code. Follow the SAP Standards and SAP Best Practices guidelines. It’s a good practice to take a dump of the code on your local drive.