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

Test for string Value in upper, lower, or mixed case

sap_cohort
Active Contributor
0 Likes
2,346

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.

1 ACCEPTED SOLUTION
Read only

awin_prabhu
Active Contributor
0 Likes
1,628

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,

4 REPLIES 4
Read only

awin_prabhu
Active Contributor
0 Likes
1,629

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,

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,628

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

Read only

Clemenss
Active Contributor
0 Likes
1,628

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

Read only

Former Member
0 Likes
1,628

bang on target Clemens,

when we can do it with a simple convert to uppercase..

then why dont you want to do this way??