ABAP SQL - SQL Expressions sql_exp
7.31 | 7.40 | 7.54
SQL expressions are expressions that can be specified in the following positions of ABAP SQL statements:
As columns specified in the
As arguments of certain aggregate expressions in
SELECTlist and in the
As operands of SQL conditions:
- On the left side of an SQL condition for statements
- On the left and right side of an SQL condition for expressions
SQL expressions are passed to the database system, executed there, and the result is passed to the AS ABAP if requested.
In general, the operands of SQL expressions can also be SQL expressions, the result of which must have a suitable data type. There are restrictions to individual operand positions, which are described for these.
The following SQL expressions exist:
- Elementary SQL expressions
- Calls of built-in SQL functions
- Arithmetic expressions
- Cast expressions
- String expressions
- Case distinctions
- Aggregate expressions
Every expression can be enclosed in parentheses. The result of an expression is used in the ABAP SQL statement in accordance with the operand position, with the data type in nested expressions being specified by the outermost expression.
No alias names defined using
AScan be used as operands of SQL expressions. This also means that none of the expressions used in a
SELECTlist can be specified as operands using their alias names.
SQL expressions cannot currently be used together with the addition
FOR ALL ENTRIES. An exception to this rule are individual columns and an individually specified aggregate expression
COUNT( * ).
- Certain SQL expressions can be calculated in the table buffer. If any other SQL expressions are used, table buffering is bypassed.
When SQL expressions are used except for individually specified columns or individually specified aggregate expressions, the syntax check is performed in a
strict mode as of Release 7.40, SP05, which handles the statement more strictly than the regular syntax check. If other SQL expressions are specified along with
aggregate expressions or
GROUP BY, the syntax check is performed in strict mode as of Release 7.40, SP08. Using aggregate expressions as operands of SQL expressions results in the strict mode as of Release 7.54.
Syntax example for specifying SQL expressions in different operand positions in a
SELECT FROM sflight FIELDS CONCAT( carrid, connid ) AS key, MAX( seatsmax - seatsocc ) AS max_free, MIN( seatsmax - seatsocc ) AS min_free GROUP BY carrid, connid HAVING SUM( seatsmax - seatsocc ) > 100 ORDER BY key INTO TABLE @DATA(itab).
This translation does not reflect the current version of the documentation.