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

Finding the word in String

Former Member
0 Likes
7,795

Dear All,

I have a requirement i.e I need to search for a particular word in a string as a condition. I can use the Offsetting but then thing is then word can be at any place in the string where we cannot use offsetting i think so.

Wat is the syntax to handle such a requirement.

Please give any sample code if possible.

Thanks

NSK

Edited by: shashikanth naram on Jun 4, 2009 12:11 PM

10 REPLIES 10
Read only

Former Member
0 Likes
3,760

Hi,

You can use FIND statement.

Press F1 on FIND for examples

Regards

Read only

GauthamV
Active Contributor
0 Likes
3,760

Plz SEARCH in SCN before posting.

Read only

Former Member
0 Likes
3,760

hi,


data: str1(20) value 'the whole string', str2(5).
if str1 CS str2.
"found word from str2 string....
else
endif.

regards,darek

Read only

Former Member
0 Likes
3,760

Hi,

To find a particulat string u can use this example coding,

if itab-field1 CA 'ABCDEFGHIJKLMONQRSTUVWXYZ0123456789+-*/$@^&()<>&~.!'.
replace all occurrences of '#' in itab-kverm1 with space    "any field which you want to select
write: /5 itab-field1
endif.
endloop.
or 

if itab-field1 CO '*'.
replace all occurrences of '*' in itab-field1 with space    "any field which you want to select
write: /5 itab-field1
endif.
endloop.

regards,

Nikhil.

Read only

Former Member
0 Likes
3,760

Cant you use:

IF string CS word

ENDIF.

Can you please explain ur requirmenet more clearly?

Read only

Former Member
0 Likes
3,760

Hi,

Refer:

Regards

Sumana

Read only

Former Member
0 Likes
3,760

Hi,

This piece of code might help you out.

REPORT  ZNIT_REPORT1.

data: str1 type string value 'Hello!!! this is nitesh',
      word(10) value 'nitesh'.
if str1 CS word.
write 'word is there'.
else.
 write 'word is not there'. 
endif.

Thanks.

Nitesh

Read only

Former Member
0 Likes
3,760

use 'CS' operator.

or you can use 'FIND' also .

use f1 help for more documentation and use of both.

Read only

venkat_o
Active Contributor
0 Likes
3,760

Hello Shashikanth, Here is the sample program which works fine.

REPORT ztest_notepad.
DATA:str_data TYPE string VALUE 'Venkat is a good guy'.

IF str_data CS 'good'.
  WRITE str_data.
ELSE.
  WRITE 'No'.
ENDIF.
Thanks

Read only

Former Member
0 Likes
3,760

try this code...

data: l_str type string.

data: l_str1 type string.

data: l_str2 type string.

l_str = 'Account determination for payment reference401'.

if l_str+43(1) NE ''.

l_str1 = l_str+0(43).

l_str2 = l_str+43(3).

concatenate l_str1 l_str2 into l_str1 separated by space.

endif.