6

In ABAP SQL can I ignore the case when comparing fields in the WHERE clause of a SELECT?

SELECT * 
FROM some_table 
WHERE field1 = variable1.

How can I compare field1 to variable1 ignoring different case?

Mike
  • 14,010
  • 29
  • 101
  • 161
Dustin Sun
  • 5,292
  • 9
  • 49
  • 87

4 Answers4

6

Open SQL can do this with the function UPPER starting ABAP 7.51.

Example:

SELECT * 
FROM some_table 
WHERE UPPER( field1 ) = @variable1
INTO TABLE @DATA(internal_table).
Mike
  • 14,010
  • 29
  • 101
  • 161
Psio
  • 83
  • 2
  • 5
4

Depending on the table you are selecting from, you may be lucky in that SAP is storing the same value in a related matchcode field, in which the value would always be upper case.

Otherwise, you may find something in the documentation of the underlying DB that allows such a search, in which case you may issue a native SELECT.

For example, if your SAP system uses Oracle as the underlying DB, you can refer to this article: http://www.dba-oracle.com/oracle_news/2005_5_20_great_technique_case_sensitive_text_searching.htm

mydoghasworms
  • 18,233
  • 11
  • 61
  • 95
  • An example of the first paragraph would be tables `EQUI` and `EQKT`. The field `EQKTU`. stores the upper case description. – Eduardo Copat Jul 19 '21 at 04:01
2

You can't. Open SQL does not support case insensitive conditions.

You can either do what mydoghasworms suggested or you filter your results using regex after data selection.

1

OpenSQL can't do this - like the others mentioned alreay in earlier statements.

But there is one alternative: Native SQL, the "upper" function, means:

translate compare_value to upper case.

exec sql performing addX.
  select * FROM  INTO :workarea
   where upper("choose_column") eq :compare_value
endexec.

form addX.
  append workarea to itab.
endform.
Hartmut Pfarr
  • 5,534
  • 5
  • 36
  • 42