ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → ABAP SQL → ABAP SQL - Operands and Expressions → ABAP SQL - SQL Conditions sql_cond
sql_cond - AND, OR, NOT, ( )
Other versions: 7.31 | 7.40 | 7.54
Syntax
... sql_cond1 AND sql_cond2 AND sql_cond3 ...
... sql_cond1 OR sql_cond2 OR sql_cond3 ...
... NOT sql_cond ...
... ( sql_cond ) ...
Effect
Any number of logical sql_cond
expressions can be joined to make one logical expression using AND
or OR
and the result of a logical expression can be negated using NOT
. The same
rules apply as to general logical expressions, with
the difference that the operator NOT
cannot be specified more than once consecutively. In particular, the explicit use of ( )
parentheses is also possible.
The following additional rules apply to logical expressions whose result is unknown (because an operand has the null value):
- An
AND
join of two unknown expressions or one true expression with an unknown expression produces an unknown expression. AnAND
join of a false expression with an unknown expression produces a false expression.
- An
OR
join of two unknown expressions or one false expression with an unknown expression produces an unknown expression. AnOR
join of one true and one unknown expression produces a true expression.
- The negation of an unknown expression with
NOT
produces an unknown expression.
Notes
- In particular, the expressions specified dynamically
as
(cond_syntax)
are also possible as logical expressions within a join or negation.
- The operator
NOT
in aWHERE
clause cannot be supported by an index. For this reason, it is best to use the reverse relational operator instead ofNOT
, for examplecol <= dobj
instead ofNOT col > dobj
.
- Two
NOT
operators can only be specified consecutively if they are separated by an opening parenthesis. If not, an even number of consecutiveNOT
s has the same meaning as none and an odd number of consecutiveNOT
s has the same meaning as a singleNOT
and should be used accordingly.
Example
Reads flights from Frankfurt to Los Angeles or San Francisco.
SELECT *
FROM spfli
WHERE cityfrom = 'FRANKFURT' AND
( cityto = 'LOS ANGELES' OR
cityto = 'SAN FRANCISCO' )
INTO TABLE @DATA(spfli_tab).