Skip to content

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 - rel_exp for Expressions

Other versions: 7.31 | 7.40 | 7.54

Syntax


 ... { {operand1 {=|EQ|<>|NE|>|GT|<|LT|>=|GE|<=|LE} operand2 } 
    | {operand  [NOT] BETWEEN operand1 AND operand2}
    | {operand1 [NOT] LIKE operand2 [ESCAPE esc]}
    | {operand  IS [NOT] NULL}
    | {operand  IS [NOT] INITIAL} } ...

Effect

Relational expression in a condition of an expression in an ABAP SQL statement. Logical expressions sql_cond can be formed from the relational expressions shown here for the following conditions:

  • Start condition of the table function HIERARCHY.

The relational expressions that can be used in expressions are a subset of the relational expressions for statements, but also allow SQL expressions as operands on the right side.

  • operand1 =|<>|>|<|>=|<= operand2
Compares the operand operand1 on the left side with the operand operand2 on the right side. The same applies to relational operators as in a condition for statements. The operands of size comparisons can have the following data types here:
  • Character-like data types: CHAR, CLNT, LANG, CUKY, UNIT, and NUMC
  • Date types, time types, and time stamp types: DATN, DATS, TIMN, TIMS, and UTCLONG
The operand operand2 on the right-hand side can be any SQL expression except aggregate expressions and window expressions. If an operand of the comparison has the null value, the result of this comparison is unknown.
  • operand [NOT] BETWEEN operand1 AND operand2
Checks the assignment to an interval. The relational expression functions in the same way as the corresponding condition for statements. The addition NOT is not possible. The operands can have the same data types as for size comparisons. For operand1 and operand2, any SQL expressions except aggregate expressions and window expressions can be specified. If one of the operands has the null value, the result of the check is unknown.
  • operand1 [NOT] LIKE operand2 [ESCAPE esc]
Pattern comparison. The relational expression functions in the same way as the corresponding condition for statements. The addition NOT is not possible. The same applies to the operands as in the condition for statements. The operands must be character-like and only literals and host variables can be specified on the right-hand side.
  • operand IS [NOT] NULL
Checks for the null value. The relational expression functions in the same way as the corresponding condition for statements.
  • operand IS [NOT] INITIAL
Checks for the initial value of the assigned elementary ABAP type. The relational expression functions in the same way as the corresponding condition for statements.

The operands on the left-hand side can be any SQL expressions except aggregate expressions and window expressions. Any occurring columns and expressions (with the exception of LIKE) can have any dictionary type except ACCP, DF16_SCL (obsolete), DF34_SCL (obsolete), LCHR, LRAW, PREC, RAWSTRING, STRING, and GEOM_EWKB. Individually specified literals, host variables, and host expressions are handled as elementary SQL expressions and can be of any ABAP type, except string and xstring.

It must be possible to compare the data types of the operands of a relational expression. If this is not the case, a statically specified type raises a syntax error and a dynamically specified type raises an exception of the class CX_SY_DYNAMIC_OSQL_SEMANTICS. Unlike in conditions for statements, operands of the types DATS and TIMS are handled like regular flat character-like operands.

If an expression is used for a selection, the client column of a client-specific data source of a query or the target of a write statement in an SQL condition of this expression cannot be used as an operand. This is due to implicit client handling.


Notes

  • Because an expression is passed to the database essentially unchanged, the possible relational expressions and their operands represent only a subset of the relational expressions for statements. In some constructs, however, a WHERE, HAVING, or ON condition of a statement is processed by the ABAP runtime environment before the pass, to ensure platform-independent behavior.

  • The addition NOT cannot currently be specified in front of BETWEEN and LIKE. Instead, the operator NOT can be used in front of the full expression.