05-02-2008 5:04 AM
Hi Guys,
Is there any way to do case sensitive comparision in ABAP. If not then what will be the work around?
eg: Vinod should not be equal to vinod.
Thanks,
Vinod.
05-02-2008 5:26 AM
Use this code..
* Local Data
DATA: l_name1 type string value 'Vinod',
l_name2 type string value 'ViNOd'.
TRANSLATE l_name1 TO UPPER CASE.
TRANSLATE l_name2 TO UPPER CASE.
IF l_name1 EQ l_name2.
* Whatever code..
ENDIF.
Please rewaqrd points if helpful..
Thanks,
Rahul
05-02-2008 5:17 AM
Hi Vinod..
just use a buffer variable and use translate to upper case...
f1 = Vinod.
f2 = vinod.
v1 = translate f1 to uppercase.
v2 = translate f2 to uppercase.
if v1 = v2.
......
...
endif.
05-02-2008 5:24 AM
You can use any of the following operators to compare for case sensitiveness too ..
CO- Contains Only
CN- Contains Not Only
CA- Contains Any
Regs,
Disha
05-02-2008 5:26 AM
Use this code..
* Local Data
DATA: l_name1 type string value 'Vinod',
l_name2 type string value 'ViNOd'.
TRANSLATE l_name1 TO UPPER CASE.
TRANSLATE l_name2 TO UPPER CASE.
IF l_name1 EQ l_name2.
* Whatever code..
ENDIF.
Please rewaqrd points if helpful..
Thanks,
Rahul
05-02-2008 6:05 AM
Hi Guys,
Thank u for ur replies. I don't want to convert the strings to upper/lower case. Is there any way to achieve this.
eg: If it is a password check then is it possible to do this?
even in SAP log on screen also it is not doing case sensitive comparision!!!.
Thanks,
Vinod.
05-02-2008 6:09 AM
in thi case.. Vinod is not equal to vinod...
if its a parameter value then u can mention extension lower case.
parameters: pa_file type string lower case.
05-02-2008 6:12 AM
hi,
just compare them using the equal (=) sign.
take a look at this example.
data:
test1 type c value 'C',
test2 type c value 'c'.
if test1 eq test2.
write 'Equal'.
else.
write 'Not Equal'.
endif.
05-02-2008 6:23 AM
Hi,
Please read the answer carefully no Upper Case/Lower Case has been used. In Parameters Lower case extension has been used so that string as it is used for comparison without converting to upper case/Lower case. In fact comparison after using Upper Case is wrong.
Regards
Raju Chitale
05-02-2008 5:42 AM
Hi,
Yes it is certainly possible. Just copy the following code & have a look at the result.
REPORT zrbckil.
parameters: w_v1(6) lower Case no-display,
w_v2(6) lower Case no-display.
DATA: w_v3(6) Value 'Vinod',
w_v4(6) Value 'viNod'.
data: w_ii type i.
w_v1 = w_v3.
w_v2 = w_v4.
If w_v1 = w_v2.
Write 'They are Same'.
Else.
Write 'They Are not same'.
Endif
I hope this helps,
Regards
Raju chitale
06-23-2011 6:38 AM
As I tested, by default the equal sign comparison is case-sensitive. That is, below code shows some result:
IF 'a' <> 'A'.
WRITE / 'Comparison is case-sensitive.'.
ENDIF.
If you want the opposite behavior, then you need to use some other methods, such as suggested in previous posts, translate to upper case and then compare.
However, SQL SELECT statement comparison is by-default case-insensitive. It is possible to configure the database server to make it case-sensitive, and there are other ways to work around that, too, such as reading the data into an internal table and do ABAP comparison. Internal table loop with where and read by key are both case-sensitive.
Note however, that domains can be defined as case-insensitive. To make comparison always case-sensitive, you should always convert non-string to a string.
06-23-2011 6:41 AM