Using SPLIT in SAP ABAP

Using SPLIT function to divide a string at a value into different variables

+ -

SPLIT is a key word which is used to cut a string into pieces at a specified value.

Keyword syntax is  SPLIT AT '<VALUE> INTO < IT_TABLE > 

Example of using SPLIT in SAP ABAP

REPORT  ZSAPN_STRING.
DATA : LV_STRING TYPE STRING . "declaration for main string
DATA : LV_STRING1 TYPE STRING, "declaration for splitting string into 
       LV_STRING2 TYPE STRING, "declaration for splitting string into 
       LV_STRING3 TYPE STRING, "declaration for splitting string into 
       LV_STRING4 TYPE STRING. "declaration for splitting string into 
LV_STRING = 'SPLIT ME AT SPACE'. "main string value
SPLIT LV_STRING AT ' ' INTO  LV_STRING1 LV_STRING2 LV_STRING3 LV_STRING4. "split 

the main string into specified fields at space
WRITE :/ LV_STRING1. "print split fields
WRITE :/ LV_STRING2.
WRITE :/ LV_STRING3.
WRITE :/ LV_STRING4.

Example of using SPLIT into internal table

Instead of splitting the data into individual fields we can split data into an internal table.
REPORT  ZSAPN_STRING.

DATA : LV_STRING TYPE STRING .
TYPES: BEGIN OF TY_STRING,

      STR(25) TYPE C,
      END OF TY_STRING.
DATA IT_STRING TYPE TABLE OF TY_STRING.
DATA WA_STRING TYPE TY_STRING .
LV_STRING = 'SPLIT ME AT SPACE'.
SPLIT LV_STRING AT ' ' INTO TABLE IT_STRING .

LOOP AT IT_STRING INTO WA_STRING.
  WRITE :/ WA_STRING-STR.
ENDLOOP.

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 30 People out of 37 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →