SEGMENT function in ABAP

light111SEGMENT 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.


1


Program Output:

2


 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s