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

Case sensitivity for search command

Former Member
0 Likes
693

Hello,

I am using SEARCH for finding patterns in strings. It works pretty fine (e.g. incl. wildcard support). However, SEARCH does not support case sensitivity (unlike otherwise one can use TRANSLATE to firce the opposite).

According to help, SEARCH does not support case - is there any solution to this or an alternative command? I do not want to create a custom function module just to emulate this and to partly reinvent the wheel.

Btw.: How can I use "match whle words" w/ SEARCH as it somehow can distinguish between delimting characters according to help document.

Thanks and regards,

Timo

6 REPLIES 6
Read only

Former Member
0 Likes
635

May be you can use the 'FIND' statement with ignoring case addition.

Example

DATA:

c TYPE STRING,

p(2) TYPE C.

c = 'Everyone knows this'.

p = 'NO'.

FIND p IN c IGNORING CASE.

After the search, sy-subrc = 0.

Regards,

ravi

Read only

0 Likes
635

Hello Revi,

Dammit, is FIND a newer ABAP command - we have a 4.6C release here and cannot find it in help nor the compiler likes it

Thanks and regards,

Timo

Read only

0 Likes
635

Hey,

<u><b>REFER THE SAP HELP marked in BOLD and UNDERLINED</b></u>

You could use the relational operator "CS" OR "CP".

Sample Program:

DATA: text(30) VALUE 'I like blogging on SDN'.

IF text CS 'IKE'.

MESSAGE i000(vz) WITH 'True'.

ELSE.

MESSAGE i000(vz) WITH 'False'.

ENDIF.

IF text CP 'IKE'.

MESSAGE i000(vz) WITH 'True'.

ELSE.

MESSAGE i000(vz) WITH 'False'.

ENDIF.

Excerpt from SAP Help on CS(Contains String):

True if the content of operand2 is contained in operand1. <u><b>Upper/lower case is not taken into account</b></u>, trailing blanks of the left operand are taken into account. If operand1 is of type string and initial, or of type c and contains only blank characters, the logical expression is false, unless operand2 is also of type string and initial, or of type c and only contains blank characters. In this case the logical expression is always true. If the result of the comparison is true, sy-fdpos contains the offset of operand2 in operand1. If the result of the comparison is negative, sy-fdpos contains the length of operand1.

Covers Pattern: True, if the content of operand1 fits the pattern in operand2. Wildcard characters can be used for forming the operand pattern, where "" represents any character string, and "+" represents any character. <u><b>Upper/lower case is not taken into account</b></u>. If the comparison is true, sy-fdpos contains the offset of operand2 in operand1, whereby leading wildcard characters "" in operand2 are ignored if operand2 also contains other characters. If the comparison is false, sy-fdpos contains the length of operand1. You can select characters in operand2 for a direct comparison by adding the escape symbol "#" before the required characters. For these characters, upper/lower case is taken into account, wildcard characters and the escape symbol itself do not receive special treatment, and trailing blanks in operands of type c are not cut off.

-Kiran

*Please mark useful answers

Message was edited by: Kiran Raorane

Read only

0 Likes
635

In that case I'm afraid , you have to atleast redesign the wheel if not reinvent it.

You have to use the translate option as you have already noted.

Regards,

Ravi

Read only

0 Likes
635

Hello Kirna,

Thank you for the suggestion, but again, case is not taken into account here, or am I wrong?

thank you and regards,

Timo

Read only

Former Member
0 Likes
635

You can do a bitwise comparison of equality:


IF fld1+i(j) = 'Whatever'.

Rob