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

How to Find a String in another String

Former Member
0 Likes
50,942

hi all,

I am using abap program ,

in this program i want to search one string in to another string.

"How to Find a String in another String"

wether abap is having some functionality? pls send me the details about it?

thanks !

regards

Raghvendra

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
14,979

Use CS .. contains string

if v_string1 CS v_string2.

endif.

Use CS .. contains string

if v_string1 CS v_string2.

endif.

6 REPLIES 6
Read only

Former Member
0 Likes
14,979

Hi,

You can use CS comparison operator for that or SEARCH statement.

Check the documentation on those keywords.

Regards,

Nicolas

Read only

Former Member
0 Likes
14,980

Use CS .. contains string

if v_string1 CS v_string2.

endif.

Read only

Former Member
0 Likes
14,979

hi,

you can use a RANGE too.

it's work for a field or an internal table.

DATA: BEGIN OF rtab OCCURS {10|n},

sign(1) TYPE c,

option(2) TYPE c,

low LIKE dobj,

high LIKE dobj,

END OF sel.

Regards,

Reward point if useful.

Read only

Former Member
14,979

Hi,

Find out the positiomn of ur string in the orginal string in sy-fdpos

DATA: text TYPE string VALUE 'Roll. .over Beethoven',

pos TYPE i.

SEARCH text FOR 'ol'.

SEARCH text FOR ` `.

IF sy-subrc = 0.

pos = sy-fdpos + 2.

SEARCH text FOR 'th' STARTING AT pos.

ENDIF.

do reward if helpful

Read only

Former Member
0 Likes
14,979

hi,

try this short example:

DATA: BEGIN OF REPORT OCCURS 0,

TEXT(255),

END OF REPORT.

*

DATA: PRG LIKE SY-REPID.

PRG = SY-REPID.

*

READ REPORT PRG INTO REPORT.

*

LOOP AT REPORT.

*

SEARCH REPORT-TEXT FOR 'LOOP'.

*

IF SY-SUBRC = 0.

WRITE: / SY-TABIX, SY-FDPOS, REPORT-TEXT(60).

ENDIF.

*

ENDLOOP.

Regards, Dieter

Read only

anoop_gupta2
Participant
14,979

hey ..

try out this code ..

lv_string = 'Hello World'.
FIND 'o' IN lv_string. "sets sy-subrc to 0 if 'o' was found, or 4 otherwise

  • if useful , Reward

thanks and regards.

Anoop Gupta