Application Development 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: 

Case sensitive comparision in ABAP?????

vinod_vemuru2
Active Contributor
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

10 REPLIES 10

former_member156446
Active Contributor
0 Kudos

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.

former_member187709
Active Participant
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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.

0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

kiran_k8
Active Contributor
0 Kudos

Vinod,

You can even use SY-ABCDE to check the CASE

Thanks,

K.Kiran