ABAP - Keyword Documentation →  ABAP - Core Data Services (ABAP CDS) →  ABAP CDS - Data Definitions →  ABAP CDS - DDL for Data Definitions →  ABAP CDS - CDS Entity Extension → 
Mail Feedback

CDS DDL - EXTEND VIEW ddic_based

Syntax

@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 CDS DDIC-based view (obsolete) ddic_based_view using a CDS DDIC-based view extension cds_view_extension in the CDS DDL. An existing CDS DDIC-based view (obsolete) can have one or more CDS DDIC-based 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 (obsolete) cannot be specified.

Prerequisite

As a prerequisite for the extension 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:

Components of a View Extension

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

Restrictions

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 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.

Note: 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.

Hints

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]
@EndUserText.label: 'Further information about the CDS entity'
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 DDIC append view DEMO_CDS_EXTENS is created in ABAP Dictionary.

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.

Hint

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;

extends 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.

Hint

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
  };

extends 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.



Continue
CDS DDL - EXTEND VIEW, extension_annot