Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Split String into two

Former Member
0 Likes
2,642

HI,

How to Split String into two parts at delimiter

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,093

HI,

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

Reward Points if found helpfull..

Cheers,

Chandra Sekhar.

2 REPLIES 2
Read only

Former Member
1,093

1. SPLIT f AT g INTO h1 ... hn.

here you can split the string f in to 2 parts h1 and h2 at delimeter g.

2. SPLIT f AT g INTO TABLE itab.

you can even add it as directly into internal table.

please reward if useful.

Read only

Former Member
0 Likes
1,094

HI,

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

Reward Points if found helpfull..

Cheers,

Chandra Sekhar.