Ansicht
Dokumentation

ABENCDS_EXTEND_VIEW - CDS EXTEND VIEW

ABENCDS_EXTEND_VIEW - CDS EXTEND VIEW

CL_GUI_FRONTEND_SERVICES - Frontend Services   ROGBILLS - Synchronize billing plans  
This documentation is copyright by SAP AG.
SAP E-Book

- EXTEND VIEW ddic_based

@AbapCatalog.sqlViewAppendName: 'CDS_APPEND_VIEW'
$[@extension_annot1$]
$[@extension_annot2$]
...
EXTEND VIEW ddic_based_view
       WITH cds_view_extension
            $[association1
             association2 ...$]
            { select_list_extension }
            $[GROUP BY field1, field2, ...  $]
            $[UNION $[ALL$] { ... }$] $[;$]


Additions

1. ... GROUP BY field1, field2, ...

2. ... UNION $[ALL$] { ... }

Effect

Extends an existing ddic_based_view using a CDS view extension cds_view_extension in the CDS DDL. An existing CDS DDIC-based view can have one or more CDS view extensions.

The extended CDS view ddic_based_view must be specified under the name of its CDS entity. The name of the CDS-managed DDIC view cannot be specified.

As a prerequisite for the enhancement of the CDS view with the statement EXTEND VIEW, the elements of the annotation array AbapCatalog.viewEnhancementCategory[ ] must be specified accordingly in its definition with DEFINE VIEW:

  • By default or if only the value #PROJECTION_LIST is specified, views without aggregate expressions in the SELECT list and without a UNION clause can be extended.
  • In order to extend views that have aggregate expressions in the SELECT list, the annotation array must contain the value #GROUP_BY alongside #PROJECTION_LIST.
  • In order to extend views that contain UNION clauses, the annotation array must contain the value #UNION alongside #PROJECTION_LIST.
  • If the annotation array contains the value #NONE, the view cannot be extended.

Components of a View Extension

View extensions can make additions to the original view, but it can't modify, overwrite, or delete elements from the original view. The following components are possible in a CDS view extension:

It is not allowed to define new CDS compositions or CDS to-parent associations in a view extension.
  • 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 all data sources of the extended view in the extension list select_list_extension. The list can have all elements of a SELECT list, namely:

  • Input parameters of the extended CDS view. It is not possible to specify new input parameters in a view extension.

  • It can expose a CDS association of the extended view or a newly defined association

  • Using a path expressions, a field of an association target can be included. Path expressions are possible for associations of the extended view or for newly defined associations.

To add aggregate expressions to a view extension, special rules apply. See below.
  • Aggregate expressions are possible in the SELECT list of a view extension only if the following conditions are met:
  • The original view must contain aggregate expressions. If the original view does not contain any aggregate expressions, this is not possible.

  • The extended view must be annotated with AbapCatalog.viewEnhancementCategory [#PROJECTION_LIST, #GROUP_BY]

  • If non-aggregated elements are added to a CDS view with aggregate expressions, then the GROUP-BY clause must be extended using the addition GROUP BY

  • If the original view contains UNION, equivalent UNION additions must be used in the statement EXTEND VIEW. As a prerequisite, the extended view must be annotated with AbapCatalog.viewEnhancementCategory [#PROJECTION_LIST, #UNION]
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.

  • CDS views with an explicit name list cannot currently be extended.
  • CDS view extensions themselves cannot be extended.
  • It is not possible to specify new input parameters in a view extension.
  • No addition ROOT can be specified in the statement EXTEND VIEW to transform a regular view to a root entity.
  • An appended field cannot be defined as a key field using KEY.
  • It is not allowed to define new to-parent or composition associations in a view extension.
  • For views that have an element of data type LRAW or LCHR in the SELECT list, no view extension is possible and the annotation AbapCatalog.viewEnhancementCategory[#NONE] is enforced. The reason is that elements of data types LRAW or LCHR must always be in the last position of the SELECT list.

Naming

Two repository 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 DDIC append view, but can have up to 30 characters.

The name of the new DDIC 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.

  • Once the DDL source code of a CDS view extension has been transported, the actual name cds_view_extension and the name of the DDIC append view CDS_APPEND_VIEW can no longer be changed. The extended view ddic_based_view can also no longer be changed.

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.

Notes

  • Currently it is not possible to define extension categories for CDS views. The following restrictions apply to this reason:
  • CDS views have the property can be extended in any way with respect to the extension category of DDIC 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.

  • CDS view extensions specified with EXTEND ENTITY are recommended for CDS DDIC-based views only. However, for compatibility and migration reasons, it is also possible to extend CDS projection views or CDS view entities with the statement EXTEND VIEW. However, view extends defined using EXTEND VIEW don't support the syntax elements specific to projection views and CDS view entities. Therefore, it is recommended that the statement EXTEND VIEW ENTITY is used for extensions of CDS projection views and CDS view entities instead.
  • If, for some reason, a CDS projection view or a CDS view entity is extended with EXTEND VIEW, the CDS-managed DDIC view is deleted (as CDS projection views and CDS view entities do not have any DDIC artefacts), and entity annotations referring to the CDS-managed DDIC view are ignored.

Example

The following CDS view extension

adds two view fields to the existing CDS view.

The DDIC 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

extends the existing CDS view.

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

extends the existing CDS view.

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.






Fill RESBD Structure from EBP Component Structure   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.

Length: 23136 Date: 20240423 Time: 091907     sap01-206 ( 162 ms )