ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Open SQL → Open SQL - Read Accesses → SELECT → SELECT - WHERE → WHERE - sql_cond
sql_cond - Relational Operators
Other versions: 7.31 | 7.40 | 7.54
Syntax
... col1 operator {dobj}
| {col2}
|
{[ALL|ANY|SOME] subquery} ...
Effect
The relational expression compares the content of the column col1
with the
content of one of the following operands, in accordance with the relational operator operator
:
- A host variable or a literal. The name
of a host variable should be prefixed with the escape character
@
. The content of the operand should match the data type of the column in accordance with the rules for lossless assignments. This is checked by the strict modes of the syntax check from Release 7.40, SP08 and can raise an exception.
- Another column
col2
of a database table or view specified after aFROM
In this casecol2
must be specified using the column selector as data_source~comp ortabalias~comp
.
- A scalar subquery
subquery
The following table shows the possible relational operators.
operator | Meaning |
---|---|
= , EQ |
True, if the content of col1 is the same as the content of the second operand. |
<> , NE |
True, if the content of col1 is not the same as the content of the second operand. |
< , LT |
True, if the content of col1 is less than the content of the second operand. |
> , GT |
True, if the content of col1 is greater than the content of the second operand. |
<= , LE |
True, if the content of col1 is less than or the same as the content of the second operand. |
>= , GE |
True, if the content of col1 is greater than or the same as the content of the second operand. |
Note the following when using these operators:
- If the second operand is an ABAP data object, it is (if necessary) converted to the data type that matches the type of the column
col1
in accordance with the tables of predefined types in ABAP Dictionary.
- If the second operand is a column of a database table or view specified after
FROM
, the types and length of both operators must be equal; otherwise the result depends on the database system.
- In greater than/less than comparisons with character-like columns, the result can depend on the code page used by the database system.
- In the case of columns that contain nothing but a blank character, it is the platform that determines how this blank is saved:
- In the SAP HANA database and in MaxDB a single blank is saved as an empty string and not as specified by the code page in question.
- In all other database and in SAP buffering, a single blank is saved in accordance with the code page.
Notes
- Host variables without the escape character
@
are obsolete. The escape character@
must be specified in the strict modes of the syntax check from Release 7.40, SP05.
- The obsolete forms
><
,=<
, and=>
of relational operators may still appear outside of classes.
- Size comparisons for character-like columns should be avoided to prevent platform-dependent behavior. An exception here are simple cases, such as columns that contain only digits.
Example
Gets flights with a seat occupancy that is less than the entered value.
DATA seatsocc TYPE sflight-seatsocc.
cl_demo_input=>request( CHANGING field = seatsocc ).
SELECT carrid, connid, fldate
FROM sflight
WHERE seatsocc < @seatsocc
INTO TABLE @DATA(sflight_tab).
Example
Gets overbooked flights.
SELECT carrid, connid, fldate
FROM sflight
WHERE seatsocc > sflight~seatsmax
INTO TABLE @DATA(sflight_tab).