ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → ABAP SQL → ABAP SQL - Operands and Expressions → ABAP SQL - SQL Operands sql_elem
ABAP SQL - col
Other versions:
7.31 | 7.40 | 7.54
Syntax
... [data_source|tabalias~]colname
| [data_source|tabalias~]sql_path-element ...
Variants
1. ... colname
2. ... sql_path-element
Addition
Effect
Specifies a column of a data source of a query or the target of a write in an ABAP SQL statement.
Columns can be specified as elementary SQL expressions in all operand positions in which SQL expressions are possible. However, they can also occur in specific operand positions in which no SQL expressions are possible.
Variant 1
... colname
Effect
Specifies a column of a data source of a
query or of the target of a
write directly using its name colname
(as defined as a component of the associated structure in ABAP Dictionary).
Note
When a column is specified, the actual names of the components must be used for a database table containing an include structure, and not the names of any groups defined in ABAP Dictionary.
Example
Columns carrid
, carrname
, and url
specified directly in the clauses of a SELECT
statement.
SELECT FROM scarr
FIELDS carrid, carrname
WHERE url = ' '
INTO TABLE @DATA(itab).
Variant 2
... sql_path-element
Effect
Specifies an element of a data source of a
CDS view after a path expression
sql_path
. This can be specified
in SELECT
statements where path expressions can be used and in all places where a column can be specified (unless otherwise indicated).
The element element
closes the path expression (compiled from
CDS associations or
CTE associations) for
which the structure component selector -
is used. This element must be an element of the target data source of the final association in the path.
Notes
- Path expressions can be used in the following
SELECT
statements:
- Statements that use the CDS entity to access a CDS view in which the used associations are published for use from outside.
- Statements in a
WITH
statement that follow common table expressions that themselves publish associations using the additionWITH ASSOCIATIONS
.
- If an element is specified after the path expression, this represents a column specified of the join created implicitly for the path expression. Left outer joins
(
LEFT OUTER JOIN
) are created for path expressions in specified columns.
source~
can be used to prefix the path expression with the unit from which its first association is published.
- When a column is specified using a path expression, the syntax check is performed in a strict mode, which handles the statement more strictly than the regular syntax check.
Example
A SELECT
statement accesses the
CDS view demo_cds_assoc_scarr that
publishes a CDS association
_spfli. As its target data source, this CDS association uses a view that publishes the CDS associations
_sflight and _sairport. The columns specified
by the SELECT
statement cover any path expressions created by these CDS associations. See also the associated executable example.
SELECT carrname,
\_spfli-connid AS connid,
\_spfli\_sairport-name AS name
FROM demo_cds_assoc_scarr
WHERE carrid = '...' and
\_spfli\_sflight-fldate > '20190515'
INTO TABLE @DATA(itab).
Addition
... data_source|tabalias~
Effect
The column selector
~
can be used to prefix every specified column directly with the name of
the associated data source of a query or of the target of a write (as data_source
or as an alias name tabalias
).
The data source must be specified in the following cases:
- If multiple data sources in an ABAP SQL statement need to be edited and the column name is not unique.
- On the right-hand side of the relational expressions
of SQL conditions
sql_cond
for statements.
Example
Using the name scarr
of a data source and the alias name connections
of a different data source in front of the column selector ~
of specified columns.
SELECT FROM scarr
INNER JOIN spfli AS connections
ON scarr~carrid = connections~carrid
FIELDS scarr~carrname, connections~connid
WHERE connections~cityfrom = '...'
INTO TABLE @DATA(itab).