SEGMENT function in ABAP
Usually we upload(CSV file or DAT file ) from the workstation into the sap program. If we have a text file with different field values in one line we can make use of SEGMENT function to read the value of each field.
Code Snippet: If we have a comma separator, the we can use SEGMENT function as shown below.
DATA result TYPE string.
DATA: lv_val TYPE string VALUE ‘ABCD,EF,GH,IJKL,MNOP,QR,STUV,W,XYZ’.
DO.
TRY.
result = segment( val = lv_val ” pass the whole line text
index = sy-index
sep = ‘,’ ). ” pass the separator value
WRITE:/ result.
CATCH cx_sy_strg_par_val.
EXIT.
ENDTRY.
ENDDO.
Program Output: