Compare strings for case sensitivity

by Vinayak

Consider the scenario where-in we need to compare the given string for the pattern 'SAP123' (CASE SENSITIVE). Even if the provided string is "SAp123" or "sap123" or "Sap123" or "SaP123" are not acceptable.

Following is a sample code to achieve this functionality:

REPORT ZCOMPARE_TEST.

PARAMETERS:
P_INPUT(10) TYPE C LOWER CASE.

IF P_INPUT CP '#S#A#P123'.
WRITE:/ 'Pattern matched'.
ELSE.
WRITE:/ 'Pattern not matched'.
ENDIF.

As observed above, we need to have '#' before every character and not needed for digits (As we do not have upper case and lower case for digits).

If you want to check for multiple patterns, then it is better to use a range. Following is the sample code for the same:

REPORT ZCOMPARE_TEST.

PARAMETERS:
P_INPUT(10) TYPE C LOWER CASE.

Data:

R_Compare type range of text10 with header line.

R_COMPARE-sign = 'I'.
R_COMPARE-OPTION = 'CP'.
R_COMPARE-LOW = '#S#A#P123'.
APPEND R_COMPARE.

if p_input IN R_COMPARE.
WRITE:/ 'Pattern matched'.
else.
Write:/ 'Pattern not matched'.
endif.
                                     

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image