ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → ABAP SQL → ABAP SQL - Operands and Expressions
ABAP SQL - SQL Expressions sql_exp
Other versions:
7.31 | 7.40 | 7.54
Syntax
... sql_elem
| sql_func
| sql_arith
| sql_cast
| sql_string
| sql_case
| sql_agg
| sql_win...
Effect
SQL expressions are expressions that can be specified in the following positions of ABAP SQL statements:
-
As columns specified in the
SELECT
list -
As arguments of certain aggregate expressions in
the
SELECT
list and in theHAVING
clause -
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
-
Window 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.
Notes
-
No alias names defined using
AS
can be used as operands of SQL expressions. This also means that none of the expressions used in aSELECT
list 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 expressionCOUNT( * )
. - 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
the addition
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.
Example
Syntax example for specifying SQL expressions in different operand positions in a SELECT
statement
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.