Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Read Accesses →  SELECT →  SELECT - FROM 

SELECT - data_source

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


... dbtab|view 
   | cds_view[( pname1 = act1, pname1 = act2, ...)] ...

Alternatives

1. ... dbtab|view

2. ... cds_view[( pname1 = act1, pname1 = act2, ...)]

Effect

Specifying a single database table or view after the addition FROM of a SELECT statement.

Alternative 1

... dbtab|view

Effect

Specifies a database table dbtab of a classic view or of an external view view defined in ABAP Dictionary. Classic views on which reads can be performed using SELECT are database views and projection views.


Example

Reads from the database table spfli and assigns the alternative name s. In this case, the prefix s~ after ORDER BY also does not need to be specified, because only one database table is read and the column name carrid is unique. The prefix spfli~ can no longer be used when assigning the alternative name.

DATA wa TYPE spfli. 

SELECT * 
       FROM spfli AS s 
       ORDER BY s~carrid 
       INTO @wa. 
  cl_demo_output=>write( wa ). 
ENDSELECT. 
cl_demo_output=>display( ). 

Alternative 2

... cds_view[( pname1 = act1, pname1 = act2, ...)]

Addition

... ( pname1 = act1, pname1 = act2, ...)

Effect

Specifies a CDS view cds_view created with the DDL of the Core Data Services. If the CDS view has input parameters, actual parameters must be assigned to these in a parenthesized list.

The following can be specified for cds_view:

  • The CDS database view using its name CDS_DB_VIEW defined in the annotation @AbapCatalog.sqlViewName. If the name CDS_DB_VIEW is used, the CDS database view is accessed directly. This is handled like any classic view and can be used in the SELECT statement together with the database tables or other classic views.
  • The CDS entity using its name cds_entity defined after DEFINE VIEW. If the name cds_entity is used, only other CDS entities can be accessed in this SELECT statement. CDS entities cannot be joined with database tables or classic views in joins or subqueries.

If a CDS view is accessed that contains input parameters or that accesses a view with parameters, but the current database system does not support views with parameters, an catchable exception is raised (see below).


Notes

  • CDS entities should always be accessed using the name cds_entity and CDS database views should not be accessed using the name CDS_DB_VIEW. In this case, the syntax check is performed in a strict mode, which handles the statement more strictly than the regular syntax check.
  • If a CDS role is defined for the CDS entity, SELECT accesses perform an implicit authorization check and only that data is read for which the current user has a CDS authorization. If the user does not have an assigned role, no data is read. If no data is read due to missing authorizations, sy-subrc is set to 4 as usual. When a CDS view is accessed using the CDS database view, no implicit authorization check is performed.
  • By default only current data is read when a CDS view is accessed. The default setting can be changed using an annotation.
  • In the case of client-specific views, the way automatic client handling is executed internally and the behavior of the addition CLIENT SPECIFIED determine whether a CDS view is accessed using the CDS entity or using the CDS database view.
  • If a CDS view contains a pool or cluster table as data source, no CDS database view is available. In this case, accesses using the CDS entity raise an exception.
  • When accessing a CDS view, the syntax check is performed in strict mode as of SP05, which handles the statement more strictly than the regular syntax check.

Addition

... ( pname1 = act1, pname1 = act2, ...)

Effect

Specifying actual parameters act1, act2, ... for input parameters pname1, pname2, ... of the CDS view in a parenthesized comma-separated list.

If input parameters are defined for the CDS view, a suitable actual parameter must be specified for each input parameter. Host variables or literals can be specified as actual parameters. The name of a host variable must be prefixed with the escape character @. The data type of the parameter must be convertible into the predefined data type in ABAP Dictionary; the predefined data type is specified by the typing of the parameter. The content of the actual parameter must match the data type of the input parameter in accordance with the rules for a lossless assignment.

Views with parameters constitute a database extension that is not supported by all database systems. However, the DDL of the ABAP CDS allows creating and accessing CDS views with parameters independent of the database system. In the same way, the syntax of the SELECT statement allows a view of this type or a view containing views with parameters as data sources, to be specified as a data source regardless of the database system. If a SELECT statement like this is executed for a database system that does not support views with parameters, a handleable exception of the class CX_SY_SQL_UNSUPPORTED_FEATURE is raised. Furthermore, accessing a view with parameters triggers a warning from the syntax check; this warning can be hidden by the pragma ##db_feature_mode[views_with_parameters].


Notes

  • There are currently no optional input parameters for CDS views and no replacement values for input parameters.
  • When parameters are passed to a view with parameters, the syntax check is performed in strict mode as of SP08.
  • 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 secondary database connection supports views with parameters. This requires the constant VIEWS_WITH_PARAMETERS of the class to be passed to the method in an internal table.
  • In an application, it is possible to use the method USE_FEATURES of the class CL_ABAP_DBFEATURES to detect at an early stage whether a view with parameters can be accessed. Detecting this does not require the exception to be caught first.