‎2009 Dec 23 2:53 PM
Is there a way to test for a specific string value in an IF Statement where the value icould be in upper, lower, or mixed case?
I'm thinking there is an easy way using the new "Regular Expressions"? I'm hoping to not have to translate the value to upper case.
example: I want to test for the word "copenhagen", but the user could have typed it in upper, lower, or mixed case.
IF USER_VALUE = "copenhagen".
I searched SDN, but could find anything specific to this.
Thanks for any help.
‎2009 Dec 23 3:10 PM
Hi Kenneth,
Try using CS relational operator. It ignores case sensitive.
Sample code,
DATA: user_value TYPE string,
len TYPE i.
user_value = 'Copenhagen'. " Value entered by user
len = STRLEN( user_value ). " Length of USER_VALUE
IF len = 10. " Actual length of ur word 'copenhagen'
IF user_value CS 'copenhagen'. " Ignores case sensitive
WRITE / user_value. " Ur code
ENDIF.
ENDIF.
Thanks,
‎2009 Dec 23 3:10 PM
Hi Kenneth,
Try using CS relational operator. It ignores case sensitive.
Sample code,
DATA: user_value TYPE string,
len TYPE i.
user_value = 'Copenhagen'. " Value entered by user
len = STRLEN( user_value ). " Length of USER_VALUE
IF len = 10. " Actual length of ur word 'copenhagen'
IF user_value CS 'copenhagen'. " Ignores case sensitive
WRITE / user_value. " Ur code
ENDIF.
ENDIF.
Thanks,
‎2009 Dec 23 3:11 PM
I think sy-abcde can be used to check for all Upper case characters.
DATA : Lstr(5) TYPE C VALUE 'Pqrst''.
IF Lstr CA SY-ABCDE.
String contains upper case character
else.
It holds only lower case characters
endif..
DATA : Lstr(5) TYPE C VALUE 'pqrst''.
IF Lstr CA SY-ABCDE.
String contains upper case character
else.
It holds only lower case characters
endif..
Can you check this
regex [:lower:]
regex [:upper:]
DATA : Lstr(5) TYPE C VALUE 'Pqrst''.
find first occurrence of regex [:lower:] in lstr.
if sy-subrc = 0.
Contains lower case.
else.
contains only upper case
endif.
Edited by: ksd on Dec 23, 2009 8:44 PM
‎2009 Dec 23 4:16 PM
Hi,
sorry I'm a simple mind:
CONVERT:
<value to check> TO UPPER CASE,
<value to compare> TO UPPER CASE.
IF <value to check> = <value to compare>.
WRITE: / 'Equal ignoring Case'.
ENDIF.Regards,
Clemens
‎2009 Dec 23 4:18 PM
bang on target Clemens,
when we can do it with a simple convert to uppercase..
then why dont you want to do this way??