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

String Operations

Former Member
0 Likes
1,205

Hi Experts,

Basically I have to search for a string in a file name,

If the string is AA , I have to follow particular step

If the string is BB , I have to follow particular step

If the string is CC, I have to follow particular step

I am trying with the statement

search 'AA' OR 'BB' OR 'CC' FOR FANME.

I am getting the error.

Could you please help.

Regards,

Irfan Hussain

1 ACCEPTED SOLUTION
Read only

vinod_gunaware2
Active Contributor
0 Likes
1,056

HI

USE string operation lie CS,CA,CP for this purpose.

<operator> Meaning

CO Contains Only

CN Contains Not only

CA Contains Any

NA contains Not Any

CS Contains String

NS contains No String

CP Matches pattern

NP Does not match pattern

To search a character field for a particular pattern, use the SEARCH statement as follows:

SEARCH <c> FOR <str> <options>.

The statement searches the field <c> for <str> starting at position <n1>. If successful, the return code value of SY-SUBRC is set to 0 and SY-FDPOS is set to the offset of the string in the field <c>. Otherwise, SY-SUBRC is set to 4.

The search string <str> can have one of the following forms.

SEARCH itab FOR 'string05' AND MARK.

CLEAR ... WITH IN BYTE MODE

CONCATENATE x1 ... xn INTO x IN BYTE MODE

FIND ... IN BYTE MODE

REPLACE ... IN BYTE MODE

REPLACE f WITH g INTO h IN BYTE MODE

SEARCH x FOR x1 IN BYTE MODE

SHIFT x ... IN BYTE MODE

SPLIT ... IN BYTE MODE

regards

vinod

7 REPLIES 7
Read only

Former Member
0 Likes
1,056

You can use :

FIND sub_string

IN section_of dobj

[ IN { BYTE | CHARACTER } MODE ]

[ { RESPECTING | IGNORING } CASE ]

[ MATCH OFFSET moff ] [MATCH LENGTH mlen ].

FIND 'AA' IN fname.

IF sy-subrc EQ 0.

"Do your operations for AA

ENDIF.

FIND 'BB' IN fname.

IF sy-subrc EQ 0.

"Do your operations for BB

ENDIF.

etc.

Read only

Former Member
0 Likes
1,056

Hi,

you can not use OR operand in the syntax of SEARCH. And the syntax is SEARCH f FOR g, where f is the string to be searched and g is the string in which the search is to be carried out.

Use different statements instead.

e.g.

search FNAME FOR 'AA'.

search FNAME FOR 'BB'.

search FNAME FOR 'CC'.

-Abhijit

Read only

Former Member
0 Likes
1,056

See this eg:

DATA string7(30) TYPE c VALUE 'This is a little sentence.'.
WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.

ULINE /1(26).
<b>SEARCH string7 FOR 'X'.</b>
WRITE: / 'X', sy-subrc UNDER 'SY-SUBRC',
               sy-fdpos UNDER 'SY-FDPOS'.
SEARCH string7 FOR 'itt   '.
WRITE: / 'itt   ', sy-subrc UNDER 'SY-SUBRC',
                   sy-fdpos UNDER 'SY-FDPOS'.

U can write as

SEARCH fname FOR 'AA'.
 perform step...

SEARCH fname FOR 'BB'.
 perform step ...

SEARCH fname FOR 'CC'.
 perform step...

Read only

vinod_gunaware2
Active Contributor
0 Likes
1,057

HI

USE string operation lie CS,CA,CP for this purpose.

<operator> Meaning

CO Contains Only

CN Contains Not only

CA Contains Any

NA contains Not Any

CS Contains String

NS contains No String

CP Matches pattern

NP Does not match pattern

To search a character field for a particular pattern, use the SEARCH statement as follows:

SEARCH <c> FOR <str> <options>.

The statement searches the field <c> for <str> starting at position <n1>. If successful, the return code value of SY-SUBRC is set to 0 and SY-FDPOS is set to the offset of the string in the field <c>. Otherwise, SY-SUBRC is set to 4.

The search string <str> can have one of the following forms.

SEARCH itab FOR 'string05' AND MARK.

CLEAR ... WITH IN BYTE MODE

CONCATENATE x1 ... xn INTO x IN BYTE MODE

FIND ... IN BYTE MODE

REPLACE ... IN BYTE MODE

REPLACE f WITH g INTO h IN BYTE MODE

SEARCH x FOR x1 IN BYTE MODE

SHIFT x ... IN BYTE MODE

SPLIT ... IN BYTE MODE

regards

vinod

Read only

0 Likes
1,056

if fielname <b>CS</b> 'AA' .

  • do something

elseif filename CS <b>'BB'</b> .

elseif finlename CS <b>'CC'</b> .

endif .

Regards

Raja

Read only

0 Likes
1,056

HI

USE THIS CODE.

~~~~~~~~~~~~~~~~~~~~~~~~


REPORT  ZVRTEST9.
Data: FILE_NAME type string.

FILE_NAME = 'DSAAEE'.

find 'AA' in FILE_NAME.

if sy-subrc eq 0.
write:'Search Successfull..perform operation for AA'.
endif.

~~~~~~~~~~~~~~~~~

CHEERS,

VIJAY RAHEJA

Read only

Former Member
0 Likes
1,056

data: C(32).

MOVE 'TWEPAACD' TO C .

WRITE:/ C.

SEARCH C FOR 'TAA' ABBREVIATED.

IF SY-SUBRC = 0.

WRITE: 'FOUND'.

ELSE.

WRITE: 'NOTFOUND'.

ENDIF.

_________________

when AA

perform 1.

when BB.

perform 2.

when cc.

perform 3.

when AA .

perform 4.

__________________________________

data: C(32).

MOVE 'TWEPAACDBBEFGHDD' TO C .

WRITE:/ C.

SEARCH C FOR 'TAA' ABBREVIATED.

IF SY-SUBRC = 0.

WRITE:/ 'FOUND'.

ELSE.

WRITE:/ 'NOTFOUND'.

ENDIF.

SEARCH C FOR 'TBB' ABBREVIATED.

IF SY-SUBRC = 0.

WRITE:/ 'FOUND'.

ELSE.

WRITE: 'NOTFOUND'.

ENDIF.

SEARCH C FOR 'TDD' ABBREVIATED.

IF SY-SUBRC = 0.

WRITE:/ 'FOUND'.

ELSE.

WRITE:/ 'NOTFOUND'.

ENDIF.

*COMMENTS:

EXECUTE this code and dont forget to mention the letter T as this is also taken into consideration for this purpose . try using 'AA' , 'BB', 'CC' , instead of 'TAA' etc and u'l know the difference.

regards,

vijay.

Message was edited by: Kan vijay