If a CDS view is defined as a
replacement object for a database table
or database view specified as a data source, the SELECT statement accesses
the CDS view and not the database table or the database view. In this case, it is recommended that the CDS view is used as a data source if possible.
The database table or view must be specified using the exact name defined for it in ABAP Dictionary. More specifically, it cannot be prefixed with the name for the
database schema. An Open SQL statement always accesses the database schema assigned to the current
database user name. In cases where the
standard connection or a
service connection is used, this is the
ABAP database schema. In cases where a
secondary connection is used, this is the database schema assigned to the
database user defined
in the secondary connection. Here, each access assumes that the database table or view exists under this exact name in the current AS ABAP ABAP Dictionary, regardless of the connection.
If the CDS entity has input parameters, actual parameters must be assigned to these in a parameters parenthesized list.
A path expression \path_expr
can be specified for CDS views with associations. This expression defines its target data source as a data source of the SELECT statement.
CDS table functions are database extensions that are not supported by all database systems. The ABAP
CDS CDS DDL, however, enables CDS entities to be created and used as data sources regardless of the
database system. In ABAP programs, CDS entities like this can also be specified as a data source of a SELECT statement regardless of the database system. The following applies here:
A handleable exception of the class CX_SY_SQL_UNSUPPORTED_FEATURE is raised
if the statement detects that the current database system does not support the feature. The same applies when CDS entities are accessed that contain CDS table functions as data sources.
When used, CDS entities like this produce syntax warnings that can be hidden using the pragma
In an ABAP program, it is possible to use the method USE_FEATURES of the class
CL_ABAP_DBFEATURES to check whether the current database system or a database system accessed using a
supports CDS table functions. This requires the constant AMDP_TABLE_FUNCTION of the class to be passed to the method in an internal table.
By default only current data is read when a CDS view is accessed. The default setting can be changed using an
If a CDS view contains a pool or
cluster table as data
source, no CDS database view is available. Accesses using the CDS entity produces a syntax check warning. When the statement is executed, an exception is raised.
Gets the data of the CDS view DEMO_CDS_SCARR_SPFLI.
SELECT * FROM demo_cds_scarr_spfli ORDER BY id, carrier, flight, departure, destination
INTO TABLE @DATA(result).
Specifies a path expression \path_expr after a CDS entity. In this case, the entity must be a
CDS view that publishes the first
association of the path expression in its SELECT list. The CDS view must be specified using its name cds_entity
defined after DEFINE VIEW. All
associations of the path expression must be published
in the SELECT lists of the CDS views in question for use from outside.
The target data source of the last association of the path expression is the data source of the current
SELECT statement. The data is read in accordance with the join conditions of the associations and the other conditions of the CDS views in question.
The path expression publishes only the elements of its target data source in the SELECT statement. If an element of this type is used as a
column specified in other clauses of the SELECT
statement and the column is assigned to the data source using the column selector ~,
an alternative table name must be defined and used here using AS. In
strict mode from Release 7.52, a path expression
in the data source of the FROM clause must always have an alternative table name defined with AS.
A CDS view cds_view with a path expression can be used in join expressions, like any other data source.
In the SELECT statement, it is not possible to access elements of the views
of the path expression that are in front of the target data source. This applies more specifically to
the elements of the specified view cds_view. Regular access to these elements is possible only if they are specified again as data sources of explicit join expressions in the statement.
The addition CLIENT SPECIFIED cannot be used if a data source is specified using a path expression.
Accesses the CDS view DEMO_CDS_ASSOC_SAIRPORT_TZ with parameter passing and a path expression with the
associations \_spfli and \_scarr in the FROM clause.
SELECT FROM demo_cds_assoc_sairport_tz( tz = 'UTC+1' ) \_spfli
\_scarr[ currcode = 'EUR' ]
AS scarr FIELDS carrname
ORDER BY carrname INTO TABLE @DATA(result).
The addition WITH PRIVILEGED ACCESS cannot be used together with a path expression
\path_expr. It is applied only to that CDS entity for which it is specified. It is not applied to the CDS entities published using associations of the specified CDS entity.
The SELECT statement accesses the results set of the common table expression.
All common table expressions can be used that were defined in the same WITH statement in front of the current SELECT statement.
If a common table expression is used as the data source, a temporary database table is accessed, which is available during the WITH statement.
Accesses the results set of the common table expression +carriers in a join
expression of the FROM clause of the main query of the statement WITH.
WITH +carriers AS ( SELECT carrid, carrname FROM scarr )
SELECT FROM +carriers INNER JOIN spfli
ON +carriers~carrid = spfli~carrid
FIELDS +carriers~carrname, spfli~connid,
WHERE spfli~carrid = 'LH' INTO TABLE @DATA(result).
Specifies an internal table @itab
whose name itab must be prefixed with the @ character.
More information can be found under SELECT - FROM @itab.
Uses SELECT to access an internal table using as an alternative to the statement
READ TABLE. Unlike READ
TABLE, the statement SELECT offers a (dynamic) WHERE condition and evaluates the field list for the
The statement is executed on the application server and the data in the internal table is not transported to the database.
DATA itab TYPE TABLE OF scarr WITH EMPTY KEY.
DATA cond TYPE string.
SELECT SINGLE FROM @itab AS carriers FIELDS carrid, carrname
WHERE (cond) INTO @DATA(wa).