Split String into two parts at delimiter

*---------------------------------------------------------------------
* 29.04.2003 |Initial Author - | This program search for a delimiter
*            |Amandeep Singh   | and split it into two parts.
*---------------------------------------------------------------------
*
* Split String into two parts at delimeter
* Current delimeter is '/'.
*
REPORT ZSTRING.

DATA: LENGTH TYPE I,
      REMAINING_LENGTH TYPE I ,
      NEXT_POINTER TYPE I    ,
      FIRST_HALF(20)  TYPE C ,
      SECOND_HALF(20) TYPE C ,
      TEMP TYPE I .


PARAMETER: WORD(35) TYPE C .    "INPUT WORD

START-OF-SELECTION.

  LENGTH = STRLEN( WORD ).      "Length of the input String

  SEARCH WORD FOR '/'.
  IF SY-SUBRC = 0 .

    IF SY-FDPOS > 0.
      MOVE WORD+0(SY-FDPOS) TO FIRST_HALF.
    ENDIF.
    TEMP = SY-FDPOS + 1.

    IF TEMP <> LENGTH.
      NEXT_POINTER = SY-FDPOS + 1.
      REMAINING_LENGTH = ( LENGTH - SY-FDPOS ) - 1.
      MOVE WORD+NEXT_POINTER(REMAINING_LENGTH) TO SECOND_HALF.
    ENDIF.

  ENDIF.


  WRITE:/'Input String:', WORD
  .

  WRITE:/'First  Half:', FIRST_HALF.
  WRITE:/'Second Half:', SECOND_HALF.

*-- End of Program


Additional add-on by Mike

Or you could just do:

split p0_source at con_tm into p0_left p0_right.
And if you have multiple splits then use a 1 field table as the target.

Remove Unwanted String
String Handling in ABAP - Removing Unwanted Char

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

ABAP Books
ABAP Programming, Object, Interview Questions, Certification Reference Books

ABAP Tips
ABAP and Samples Program Codes for Abapers

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.