ABAP Keyword Documentation → ABAP Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Views → ABAP CDS - DDL Statements
ABAP CDS - EXTEND VIEW
Other versions:
7.31 | 7.40 | 7.54
Syntax
@AbapCatalog.sqlViewAppendName: 'CDS_APPEND_VIEW'
[@extension_annot1]
[@extension_annot2]
...
EXTEND VIEW cds_entity WITH cds_view_extension{ select_list_extension } [;]
Effect
Enhances an existing CDS view cds_entity using a CDS view enhancement cds_view_extension in CDS source code. The enhancement adds the elements of the specified enhancement list select_list_extension to the SELECT list of the existing view as view fields without making modifications. The annotation AbapCatalog.sqlViewAppend must be specified before the view enhancement itself is defined using EXTEND VIEW. Further annotations extension_annot1, extension_annot2, ... can also be specified. This is optional.
Two ABAP Dictionary objects are created for a CDS view enhancement that is defined using EXTEND VIEW. A name must be specified for each of the two objects:
- The name CDS_APPEND_VIEW for a classic append view must be specified in quotation marks after the annotation @AbapCatalog.sqlViewAppendName created when the CDS view enhancement was activated. This name is subject to the same rules as the name of a classic view in ABAP Dictionary. The new append view enhances the CDS database view of the enhanced CDS view.
- The actual name cds_view_extension of the CDS view enhancement is specified after the keywords EXTEND VIEW. This name follows the same as the name of the append view, but can have up to 30 characters.
The enhanced CDS view must be specified under the name of its CDS entity. The name of the CDS database view cannot be specified here. It is possible to access all fields of the data sources used in the enhanced CDS view in the enhancement list select_list_extension. The list can have all elements of a SELECT list with the exception of input parameters, path expressions, and aggregate expressions. If an appended elementary field already occurs in the existing SELECT list or if a different enhancement occurs, it must be given an alternative element name using AS. An appended field cannot be defined as a key field using KEY.
The following CDS views cannot currently be enhanced:
- Views with an explicit name list
- Views with a GROUP-BY clause
- Views with a UNION clause for union sets
CDS view enhancements cannot themselves be enhanced.
Notes
- Every CDS view enhancement has its own CDS source code. The CDS source code in a CDS view enhancement is edited in a different editor from the CDS source code of a CDS view. The ADT documentation describes how these types of source code are created.
- An existing CDS view can be enhanced using multiple CDS view enhancements.
- The name of the new append view and of the actual CDS view enhancement should be located in the customer namespace (or in the namespace of a partner or special development) to protect it against being overwritten by upgrades or new releases.
- It is not currently possible to define enhancement categories for CDS views, which causes the following restrictions:
- CDS views have the property can be enhanced in any way with respect to the enhancement category of structures. The consequences of this must be respected when enhancing a CDS view.
- Functional enhancements, such as adding aggregate functions and the corresponding changes to the GROUP-BY clause or enhancements to join expressions or other clauses are not currently supported. New enhancement categories are required for enhancements like these.
- The attributes of a CDS view defined using annotations, such as switching on SAP buffering, cannot currently be modified using enhancements.
- It is advisable to contact SAP before enhancing CDS views from basis packages.
Example
The following CDS view enhancement
extend view demo_cds_original_view with demo_cds_view_extension
{ spfli.distance,
spfli.distid as unit };
adds two view fields to the existing CDS view
define view demo_cds_original_view
as select from spfli
join scarr on scarr.carrid = spfli.carrid
{ key scarr.carrname as carrier,
key spfli.connid as flight,
spfli.cityfrom as departure,
spfli.cityto as destination }; .
The classic append view DEMO_CDS_EXTENS is created in ABAP Dictionary.
The program DEMO_CDS_VIEW_EXTENSION uses the statement
SELECT
to access the enhanced view and also displays the components of the dictionary structures in question.