The elements of the annotation array AbapCatalog.viewEnhancementCategory[
] must be specified accordingly using
DEFINE VIEW in its definition before the CDS view cds_entity can be extended using the statement EXTEND VIEW:
By default (or if the value #PROJECTION_LIST is specified), views can be extended without
aggregate expressions in the SELECT
list and without a UNION clause.
Alongside #PROJECTION_LIST, the annotation array must contain the value #GROUP_BY before views with
aggregate expressions can be extended.
Alongside #PROJECTION_LIST, the annotation array must contain the
value #UNION before views with UNION clauses can be extended.
If the annotation array contains the value #NONE, the view cannot be extended.
CDS views with an explicit name list cannot currently be extended. CDS view extensions themselves cannot be extended.
EXTEND VIEW is used to make the following modification-free extensions:
The elements of the extension list select_list_extension specified
after EXTEND VIEW are added to the existing SELECT
list. At least one element must be added. It is possible to access all fields of the data sources used in the extended CDS view in the extension list select_list_extension. The list can have all
elements of a SELECT list, except
aggregate expressions. The following can also be specified:
If an appended element already occurs in the existing SELECT list or if
a different extension occurs, it must be given an alternative element name using AS. An appended field cannot be defined as a key field using KEY.
The optional associations association1,
association2, ...
specified after EXTEND VIEW can be added to the existing SELECT statement.
If the original view contains aggregate expressions,
further aggregate expressions can be added to it in select_list_extension.
If the original view does not contain any aggregate expressions, this is not possible. If other elements
are added to a CDS view with aggregate expressions, its
GROUP-BY clause must be extended accordingly using the addition GROUP BY of the association EXTEND VIEW
If the original view contains UNION,
equivalent UNION additions must be used in the statement EXTEND VIEW.
Two ABAP Dictionary objects are created for a CDS view extension that is defined using EXTEND VIEW. A name must be specified for each of the two objects:
The actual name cds_view_extension of the CDS view extension is specified after the keywords EXTEND VIEW. This name follows the same rules as the name of an
append view, but can have up to 30 characters.
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 extension was activated. This name is subject to the same rules as the name of a classic
view in ABAP Dictionary. The new append view extends the
CDS database view
of the extended CDS view. The name given to the append view can no longer be changed after the CDS view is transported into a follow-on system.
Every CDS view extension has its own
DDL source code. The DDL source code in a CDS view extension is edited in a different editor from the DDL source code of a
CDS view. The ADT documentation describes how these types of source code are created. DDL source code can also be displayed in
Repository Browser in ABAP Workbench.
An existing CDS view can be extended using multiple CDS view extensions.
The name of the new append view and of the actual CDS view extension 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.
Currently it is not possible to define extension categories for CDS views. The following restrictions apply for this reason:
CDS views have the property can be extended in any way with respect to the
extension category of structures. The consequences of this must be respected when extending a CDS view.
The attributes of a CDS view defined using annotations, such as switching on
table buffering, cannot currently be modified using extensions.
It is advisable to contact SAP before extending CDS views from basis packages.
The DDL source code of a CDS view extension does not need to have the same name as the CDS view extension entity, but it is advisable to use the name of the entity.
Once the DDL source code of a CDS view extension has been transported, the following relationships are committed and can no longer be changed:
The combination of the name of the source code and the names of the view extension defined there and its APPEND view. These can no can longer be modified by being renamed.
The assignment of the view extension to the extended view. The name cds_entity after EXTEND VIEW can no longer be modified.
Example
The following CDS view extension
@AbapCatalog.sqlViewAppendName: 'DEMO_CDS_EXTENS' 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.
@AbapCatalog.sqlViewName: 'DEMO_CDS_ORIG' @AccessControl.authorizationCheck: #NOT_REQUIRED
@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST] 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.
Addition 1
... GROUP BY field1, field2, ...
Effect
This addition must be specified if elements not defined using aggregate expressions are added to a view with
aggregate expressions. These elements
must be specified after GROUP BY add extend the GROUP-BY clause of the original view. With respect to the extended
view, the extended GROUP-BY clause must follow the general rules for a GROUP-BY clause.
The addition cannot be specified if the definition of the original view does not contain any aggregate expressions in its SELECT list.
Note
Extensions of a view with aggregate expressions require it to contain the annotation array viewEnhancementCategory[ ] with the value #GROUP_BY.
Example
The following CDS view extension
@AbapCatalog.sqlViewAppendName: 'DEMO_CDS_EXTAGG' extend view demo_cds_aggregate with demo_cds_extend_aggregate
{ connid, sum(distance) as sum_distance } group by connid;
adds two view fields to the existing CDS view.
@AbapCatalog.sqlViewName: 'DEMO_CDS_AGG' @AccessControl.authorizationCheck: #NOT_REQUIRED
@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST,#GROUP_BY] define view demo_cds_aggregate
as select from spfli { carrid, sum(fltime) as sum_fltime } group by carrid;
A database field connid and an aggregate expression sum(distance)
are added to the SELECT list. Accordingly, the addition GROUP
BY must be used to add the database field to the GROUP-BY clause of the original view.
Addition 2
... UNION [ALL] { ... }
Effect
This addition must be specified when a view with UNION
clauses is extended. A corresponding UNION addition must be specified
for each UNION clause of the original view. The addition ALL
must be specified each time it is specified in the associated UNION clause
of the original view. The curly brackets can contain elements that extend the SELECT
list of the associated UNION clause of the original view. As specified
by the SELECT list extended using select_list_extension,
the UNION clauses must be extended so that the rules for UNION clauses are not broken in the extended view.
The addition cannot be specified if the definition of the original view does not have a UNION clause.
Note
Extensions of a view with UNION clauses require it to contain the annotation array viewEnhancementCategory[
] with the value #UNION.
Example
The following CDS view extension
@AbapCatalog.sqlViewAppendName: 'DEMO_CDS_EXTUNI' extend view demo_cds_union with demo_cds_extend_union
{ c as c3, d as c4 } union { f as c3, g as c4 } union all { k as c3, l as c4 };
adds two view fields to the existing CDS view.
@AbapCatalog.sqlViewName: 'DEMO_CDS_UIO' @AccessControl.authorizationCheck: #NOT_REQUIRED
@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST,#UNION] define view demo_cds_union as select from
demo_join1 { a as c1, b as c2 } union select from demo_join2 { d as c1,
e as c2 } union all select from demo_join3 { i as c1, j as c2 };
The original view has two UNION clauses represented using corresponding
UNION additions in the definition of the CDS view extension. Two elements with matching types are added to the three SELECT lists of the original view.