ABAP Keyword Documentation → ABAP - Dictionary → ABAP CDS in ABAP Dictionary → ABAP CDS - Data Definitions → ABAP CDS - DDL for Data Definitions
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
[association1 association2 ...]
{ select_list_extension }
[GROUP BY field1, field2, ... ]
[UNION [ALL] { ... }] [;]
Extras
1. ... GROUP BY field1, field2, ...
2. ... UNION [ALL] { ... }
Effect
Extends an existing CDS view cds_entity using a CDS view extension cds_view_extension in the CDS DDL. The extended CDS view must be specified under the name of its CDS entity. The name of the CDS database view cannot be specified here.
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:
- Input parameters of the extended CDS view
- Path expressions for dedicated CDS associations and for CDS associations of the extended CDS view
- The optional CDS 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.
The annotation AbapCatalog.sqlViewAppendName must be specified before the view extension 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 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 database 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 extension is transported into a follow-on system.
CDS view extensions are connected to Switch Framework whenever they are defined in a package that is assigned a switch.
Notes
- 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 make extensions to CDS views from basis packages only after discussing them with SAP. These extensions are intended for internal use only and can be modified in incompatible ways.
- 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
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
@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
extend view demo_cds_aggregate with demo_cds_extend_aggregate
{
connid,
sum(distance) as sum_distance
}
group by
connid;
extends the existing CDS view
@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
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
};
extends the existing CDS view
@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.