Önceki Sayfa

Split String into two parts at delimiter

*---------------------------------------------------------------------

*            |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

Copyright © 2010. KM Group. All Rights Reserved.