2007 Jul 21 4:03 PM
I need to compare 2 strings using a pattern and i need the compare to be case sensitive.
CP is not case sensitive
CA is case sensitive - but it wont search for my specific pattern - it will find strings where any of the charaters match. I need to match on the whole search string.
Example: searching all long text fields that contain pattern Rm167.
my results are returning rm167, RM167 and Rm167.
How do i find ONLY Rm167 ?
Please help,
2007 Jul 21 4:53 PM
Hi. You may want to try this. When using the CP operator, there are some escape characters which will help when processing strings. So here, in this example str3 will only be matched. If you want to make the comparison case sensitive, you should put a # sign in front of the specific letter in the liternal. IN this case you want to match all.
report zrich_0001.
data: str1 type string.
data: str2 type string.
data: str3 type string.
str1 = 'rm167'.
str2 = 'RM167'.
str3 = 'Rm167'.
if str1 cp '#R#m#1#6#7'.
write:/ 'Str1 matched'.
endif.
if str2 cp '#R#m#1#6#7'.
write:/ 'Str2 matched'.
endif.
if str3 cp '#R#m#1#6#7'.
write:/ 'Str3 matched'.
endif.
Check the help on CP.
http://help.sap.com/saphelp_webas620/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/frameset.htm
Regards,
RIch Heilman
2007 Jul 21 4:04 PM
2007 Jul 21 4:36 PM
Hi Julia,
The comparision string should be like this in case of CA only '<b>Rm</b>'
Reward if useful!
2007 Jul 21 4:38 PM
Thank you
so do insert the <b> in front of my letters and </b> after my letters
and still use the CA ?
also what does the <b> stand for - what does it mean?
thanks
2007 Jul 21 4:47 PM
i am testing using <b> and </b> == but still getting the same results.
i am still matching on 'rm167' and i only want to match on 'Rm167'
please help
2007 Jul 21 4:46 PM
Hi Julia,
It should be according to your requirement.
<b>CA:</b>
<f1> CA <f2>
is true if <f1> contains at least one character from <f2>. The comparison is case-sensitive. If the comparison is true, the system field SY-FDPOS contains the offset of the first character of <f1> that also occurs in <f2> . If it is false, SY-FDPOS contains the length of <f1>.
e.g:
'ABcde' CA 'Bd ' true = 1
'ABcde' CA 'bD ' false = 5
Reward if useful!
2007 Jul 21 4:48 PM
Hi,
Your comparison operator should be '=' and not '=='
Reward if useful!
2007 Jul 21 4:51 PM
Hi Julio,
the characters of pattern must be prededed by # to make it case-sensitive.
i.e. 'ABcde' CP '#b' results in false
<a href="http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/content.htm">Comparisons Between Character Strings and Byte Strings</a>
Regards,
Clemens
2007 Jul 21 4:53 PM
Hi. You may want to try this. When using the CP operator, there are some escape characters which will help when processing strings. So here, in this example str3 will only be matched. If you want to make the comparison case sensitive, you should put a # sign in front of the specific letter in the liternal. IN this case you want to match all.
report zrich_0001.
data: str1 type string.
data: str2 type string.
data: str3 type string.
str1 = 'rm167'.
str2 = 'RM167'.
str3 = 'Rm167'.
if str1 cp '#R#m#1#6#7'.
write:/ 'Str1 matched'.
endif.
if str2 cp '#R#m#1#6#7'.
write:/ 'Str2 matched'.
endif.
if str3 cp '#R#m#1#6#7'.
write:/ 'Str3 matched'.
endif.
Check the help on CP.
http://help.sap.com/saphelp_webas620/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/frameset.htm
Regards,
RIch Heilman
2007 Jul 21 5:02 PM
selection_option s_ltxt for TLINEs-tdline.
s_ltxt = ICP#R#m#1#6#7
t_first_print-zztline1 = rm167
if t_first_print-zztline1 in s_ltxt or
t_first_print-zztline2 in s_ltxt or
t_first_print-zztline3 in s_ltxt.
keep_notif = 'Y'.
endif.
my flag keep_notfi is being set to Y when it should not match on the little letters
2007 Jul 21 5:19 PM
2007 Jul 21 7:08 PM
Yes - i did append.
and nothing has worked yet. I have tried all that have been posted here.
if anyone has an answer - even an ugly one - i will give it a try.
My user is VERY picky and I must provide this functionality.
2007 Jul 21 7:48 PM
Hi Julia,
OK I tried for you. It should make no difference so I did not use any # character in front of digits because there are no upper or lower case digits on this planet.
I got this output
Rm167 is matched by pattern #R#m167
rm167 is not matched by pattern #R#m167
RM167 is not matched by pattern #R#m167
rM167 is not matched by pattern #R#m167
using this code:
FORM ANY .
DATA:
lr_text TYPE RANGE OF text40 with header line,
lv_text1 type text40 value 'Rm167',
lv_text2 type text40 value 'rm167',
lv_text3 type text40 value 'RM167',
lv_text4 type text40 value 'rM167'.
lr_text-sign = 'I'.
lr_text-option = 'CP'.
lr_text-low = '#R#m167'.
APPEND lr_text.
IF lv_text1 IN lr_text.
WRITE: / lv_text1, 'is matched by pattern', lr_text-low.
ELSE.
WRITE: / lv_text1, 'is not matched by pattern', lr_text-low.
ENDIF.
IF lv_text2 IN lr_text.
WRITE: / lv_text2, 'is matched by pattern', lr_text-low.
ELSE.
WRITE: / lv_text2, 'is not matched by pattern', lr_text-low.
ENDIF.
IF lv_text3 IN lr_text.
WRITE: / lv_text3, 'is matched by pattern', lr_text-low.
ELSE.
WRITE: / lv_text3, 'is not matched by pattern', lr_text-low.
ENDIF.
IF lv_text4 IN lr_text.
WRITE: / lv_text4, 'is matched by pattern', lr_text-low.
ELSE.
WRITE: / lv_text4, 'is not matched by pattern', lr_text-low.
ENDIF.
ENDFORM. " any
Hope this will help you to make your picky users happy again.
Regards,
Clemens
2007 Jul 21 8:34 PM
Thank you Clemens!
This worked!
I really appreciate everyone's help today - but Clemens made it happen.