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

string function for ignoring case while comparison

Former Member
0 Likes
8,391

Hi everyone,

Is there any function to ignore case of two alphanumeric strings while their comparison.For ex.

string1: M23456n

string2:m23456n

When i compare these two strings,i want them to be equal,i.e. the case to be ignored.

Please help.

Thanks in advance,

Meena.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,207

Hi

Try

DATA : VAL1 TYPE STRING VALUE 'M23456n',
       VAL2 type string value 'm23456n'.

TRANSLATE VAL1 TO UPPER CASE.
TRANSLATE VAL2 TO UPPER CASE.


IF VAL1 = VAL2.

WRITE 'Same'.

ENDIF.

Regards

6 REPLIES 6
Read only

rainer_hbenthal
Active Contributor
0 Likes
3,207

you have to use temp variables for that. copy the values to the tempory variables, translate them to uppercase and comapre them.


data:
  s1 type string,
  s2 type string,
  t1 type string,
  t2 type string.

start-of-selection.
  s1 = `M23456n`.
  s2 = `m23456n`.

  t1 = s1.
  t2 = s2.
  translate t1 to upper case.
  translate t2 to upper case.

  if t1 = t2.
    perform do_something.
  endif.

Read only

Former Member
0 Likes
3,207

Use the two strings one by one in the function module 2054_TRANSLATE_2_UPPERCASE and store them in say str1 and str2

then compare them

Read only

Former Member
0 Likes
3,208

Hi

Try

DATA : VAL1 TYPE STRING VALUE 'M23456n',
       VAL2 type string value 'm23456n'.

TRANSLATE VAL1 TO UPPER CASE.
TRANSLATE VAL2 TO UPPER CASE.


IF VAL1 = VAL2.

WRITE 'Same'.

ENDIF.

Regards

Read only

Former Member
3,207

Hi Meena,

Go for the following code snippet.

DATA: a TYPE string VALUE 'M23456n',

b TYPE string VALUE 'm23456N'.

IF a CS b.

WRITE 'true'.

ENDIF.

For detailed info refer this.

NS (contains No String)

The logical expression

<f1> NS <f2>

is true if <f1> does not contain the string <f2>. Trailing spaces are ignored and the comparison is not case-sensitive. If the comparison is true, the system field SY-FDPOS contains the length of <f1>. If it is false, SY-FDPOS contains the offset of <f2> in <f1> .

Thanks

NItesh

Read only

0 Likes
3,207

Hi all,

Scenario is like this:

I have an interface,XI team sends an idoc.This idoc name is a sring. I have my own idoc ,so we have to compare the two idocs,i.e. the strings are suppose to be passed at run time.

Read only

0 Likes
3,207

Thanks a lot guys....but TRANSLATE helped me and i got the desired result.