ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → ABAP SQL → ABAP SQL - Operands and Expressions → ABAP SQL - SQL Expressions sql_exp
sql_exp - sql_elem
7.31 | 7.40 | 7.54
| literal | @dobj | @( expr ) ...
Elementary expression in ABAP SQL. An elementary SQL expression represents one of the following values:
Value from the database
colof a data source
colcan be of any elementary data type from ABAP Dictionary, unless otherwise documented for an operand position.
Values of the ABAP program passed to the database system
- Host variable
- Host expression
@( expr )
xstringand the name of a host variable must be tagged with the escape character
@. Literals are handled strictly according to type. This means that string literals are not allowed and only text field literals of the type
ccan be used as character literals. Empty text field literals cannot be specified. The value of a numeric literal must be in the value range of type
i, which means it always has type
The result of an elementary SQL expression is the value of the specified object or the result of the specified expression. If a value from the database is specified, the data type is its dictionary type. When an ABAP object is specified, the ABAP type is mapped to a dictionary type as follows:
|Numeric ABAP Type||Dictionary Type|
||INT1, INT2, INT4, INT8|
||DEC with appropriate length and decimal places|
|Character-Like ABAP Type||Dictionary Type|
||CHAR with appropriate length|
||NUMC with appropriate length|
|Byte-Like ABAP Type||Dictionary Type|
||RAW with appropriate length|
|ABAP Type for Date, Time, and Time Stamp||Dictionary Type|
Text field literals are handled as fields with the type CHAR and the appropriate length. Any closing blanks are respected. Like any number literal of an ABAP program, number literals are handled either as a field with the type INT4 or the type DEC, depending on the value in question. Text string literals are not allowed.
On the database, the value of an ABAP object as an elementary expression is handled by the rules of the database in accordance with the mapped type. This behavior is different from other operand positions of ABAP objects in ABAP SQL, where they are not handled as elementary expressions. In these operand positions, the content is converted to the target type in accordance with the rules for lossless assignments.
- Columns, literals, host variables, and host expressions can also occur as elementary
SQL operands in operand positions in which no SQL expressions
are possible. Columns, literals, hosts variables, and host expressions can only be handled as SQL expressions in positions where SQL expressions are possible. For example, these are the only places where they can be given
parentheses. In this case, the statement can
only have lists separated by commas and host variables must be indicated by the escape character
- If an elementary SQL expression consists of a host variable in the form of a field symbol or formal parameter, this expression must be typed in full.
- Literals, host variables, and host expressions as operands of other SQL expressions are evaluated
before the ABAP SQL statement is sent to the database system. Specifying a host variable from a
SELECT list after
SELECTloop does not mean that a different value is used in each loop pass.
- The fact that literals, host variables, and host expressions are mapped to specific dictionary types as operands of SQL expressions, whereas other operand positions permit conversions to different target types, is particularly significant for relational expressions in which the comparability of dictionary types is important.
- If required, a specified column
colcan contain a path expression for CDS associations or CTE associations.
- An elementary expression can always be evaluated in the table buffer. If an elementary expression is specified, table buffering is not bypassed.
- If a host expression is used as an argument of another SQL expression, the syntax check is performed in a strict mode from Release 7.50, which handles the statement more strictly than the regular syntax check.
SELECT list of the second
SELECT statement contains all possible elementary SQL expressions.
DATA carrid TYPE scarr-carrid VALUE 'LH'. cl_demo_input=>request( CHANGING field = carrid ). SELECT FROM scarr FIELDS carrid, carrname INTO TABLE @DATA(carriers). SELECT SINGLE FROM spfli FIELDS '*' AS mark, @carrid AS id, @( carriers[ carrid = carrid ]-carrname ) AS carrier, connid WHERE carrid = @carrid INTO @DATA(result). cl_demo_output=>display( result ).