Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
AndreaUS
Product and Topic Expert
Product and Topic Expert
21,796

This blog post provides an overview of all available types of CDS extensions.

Overview of CDS entity extensions

Statement Can be used for Available since

EXTEND VIEW ENTITY
    • CDS view entity
    • CDS projection view
7.87 | 1911 | 7.55
EXTEND CUSTOM ENTITYCDS custom entity7.89 | 2208 | 7.57
EXTEND ABSTRACT ENTITYCDS abstract entity7.84 | 2105 | 7.56
EXTEND VIEWCDS DDIC-based view7.40, SP08

EXTEND VIEW ENTITY

The statement EXTEND VIEW ENTITY is a replacement of EXTEND VIEW, designed for the extension of CDS view entities and CDS projection views.

Differences Between View Extensions and View Entity Extensions

    • A view entity extension does not have a DDIC append view.
    • CDS view extends with EXTEND VIEW require you to define at least one view field. This requirement has been removed. CDS view entity extensions also work without any new field. You can, for example, define only a new association.
    • For a view entity extension, no name is specified after WITH. A view entity extension has only one name, which is the name of the repository object. This name is assigned in the wizard for creating a new repository object.
    • In view entity extensions, no header annotations are allowed. That means that no annotations are allowed in front of the statement EXTEND VIEW ENTITY.
    • View entity extensions were developed for CDS view entities and they have the same advantages, for example, much better activation performance and new features, such as typed literals and improved currency and quantity handling.

An existing CDS view can have one or more CDS view entity extensions. A CDS entity extension can not be further extended.
Both kinds of view extensions, EXTEND VIEW and EXTEND VIEW ENTITY, can be used for all three kinds of CDS views (CDS view entities, CDS projection views, CDS DDIC-based views). This is supported for migration and compatibility reasons, but it is not recommended.

How to extend a CDS view entity

Prerequisites

The header annotation @AbapCatalog.viewEnhancementCategory[ ] specifies how a CDS view entity can be extended. The possible values are:

  • #PROJECTION_LIST: Extensions of the SELECT list and additional CDS associations are allowed
  • #GROUP_BY: can only be specified together with #PROJECTION_LIST. Allows extensions to views that have aggregate expressions in the SELECT list.
  • #UNION: Can only be specified together with #PROJECTION_LIST. Allows extensions to views that use a clause with a set operator (UNION, EXCEPT, INTERSECT).
  • #NONE: Extensions are not allowed.

What can be extended?

    • New fields can be added.
    • New associations can be defined and exposed.
    • All kinds of elements that are allowed in the SELECT list of the respective entity (CDS view entity or CDS projection view) can be added in the extension. That means that a CDS view entity extension to a CDS view entity can define elements such as path expressions, typed literals, expressions, and functions. A CDS view entity extension to a CDS projection view can define elements such as virtual elements, localized elements, and redefined associations.

Restrictions

    • New input parameters are not possible.
    • A regular view entity cannot be transformed into a root view entity.
    • An appended field cannot be defined as key field.
    • No new header annotations can be defined.

Example

The following CDS view entity allows extensions of the SELECT list.

 

@AccessControl.authorizationCheck: #NOT_REQUIRED
@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST]
@EndUserText.label: 'Further information about the CDS entity'
define view entity DEMO_CDS_ORIGINAL_VIEW_VE 
  as select from
           spfli
      join scarr on
        scarr.carrid = spfli.carrid
    {
      key scarr.carrname     as carrier,
      key spfli.carrid       as carrierId,
      key spfli.connid       as flight,
          spfli.cityfrom     as departure,
          spfli.cityto       as destination
    }; 

 

The following CDS view entity extension defines and exposes a new association:

 

extend view entity DEMO_CDS_ORIGINAL_VIEW_VE with
association [1..*] to sflight as _sflight 
  on $projection.carrierId = _sflight.carrid
{
  _sflight
}

 

EXTEND CUSTOM ENTITY

CDS custom entity extensions can be used to add elements to a custom entity without making any modifications to the original entity.

  • Prerequisite: the extended entity must allow extensions. Extensions are allowed per default or can be explicitly allowed with the annotation @AbapCatalog.extensibility.extensible with the value true.
  • Extension elements: New elements, new associations, and new compositions can be defined in the extension.
  • Restrictions:
    • New input parameters are not possible.
    • A custom entity cannot be turned into a root entity by an extensions.
    • Defining new header annotations is not supported.
    • Defining new to-parent associations in an extension is not supported.
    • No new key elements can be defined.

Example

The following CDS custom entity extension

 

extend custom entity DEMO_CDS_ORIGINAL_CUSTOM with 
{ 
  col4    : abap.char(1); 
  _assoc  : association to DEMO_CDS_CUSTOM_ENTITY  
    on $projection.col2 = _assoc.id; 
  _compos : composition [0..1] of DEMO_CDS_CUSTOM_CHILD; 
}

 

extends the existing CDS custom entity

 

@EndUserText.label: 'CDS custom entity, extended entity' 
@AbapCatalog.extensibility.extensible: true 
define root custom entity DEMO_CDS_ORIGINAL_CUSTOM 
  with parameters 
    param1 : abap.int4 
{ 
  key col1 : abap.char( 5 ); 
      col2 : abap.int4; 
      col3 : abap.int4; 
} 

 

EXTEND ABSTRACT ENTITY

CDS abstract entity extensions were designed specifically to extend CDS abstract entities. Here’s a short overview of the rules:

  • Prerequisite: As a prerequisite, the extended entity must allow extensions. Extensions are allowed per default or can be explicitly allowed with the annotation @AbapCatalog.extensibility.extensible with the value true.
  • Elements of the extension: New elements and new associations can be defined in the extension.
  • Restrictions: New input parameters are not possible. An abstract entity cannot be turned into a root entity by an extensions. Defining new header annotations is not supported.

Example

The following CDS abstract entity allows extensions:

 

@EndUserText.label: 'CDS abstract entity with extension'
@AbapCatalog.extensibility.extensible: true
define abstract entity DEMO_CDS_ORIGINAL_ABSTRACT
  with parameters
    param1 : abap.int4
{
  col1 : abap.char( 5 );
  col2 : abap.int4;
  col3 : abap.int4;
}

 

A new field and a new association are added by the following CDS abstract entity extension:

 

extend abstract entity DEMO_CDS_ORIGINAL_ABSTRACT with
{
  col4   : abap.char( 1 );
  _assoc : association to demo_cds_abstract_entity  
             on $projection.col1 = _assoc.col1;
}

 

The following program evaluates the structure of the enhanced CDS abstract entity using RTTI methods:

 

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA(out) = cl_demo_output=>new( ).
    DATA(components) =
      CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_name(
                                  'DEMO_CDS_ORIGINAL_ABSTRACT' )
                               )->components.
    out->write( components ).

    cl_dd_ddl_annotation_service=>get_direct_annos_4_entity(
      EXPORTING
        entityname =    'DEMO_CDS_ORIGINAL_ABSTRACT'
      IMPORTING
        annos      =    DATA(annos) ).
    out->write( annos ).
*
    DATA(struct) = VALUE demo_cds_original_abstract(
       col1 = 'hallo'
       col2 = 333
       col3 = 2
       col4 = 'A' ).
    out->write( struct ).
    out->display( ).
  ENDMETHOD.
ENDCLASS.


START-OF-SELECTION.

  demo=>main( ).

 

The result set contains the column added via the extension:

Further information on CDS entity extensions is available in the ABAP Keyword Documentation, secion about CDS entity extensions.

22 Comments
carlin_willams
Participant
0 Kudos
Hi Andrea,

Thanks for nice blog.

If we want to extend one more condition in where clause of standard Consumption View how can we extend. Please guide me.

define view C_SlsDocFlfmtSlsDocTypeVH

as select from I_SalesDocumentType as SalesDocumentType

association [0..*] to I_SalesDocumentTypeText  as _Text on $projection.SalesDocumentType = _Text.SalesDocumentType

{

@ObjectModel.text.association: '_Text'

@Search.defaultSearchElement: true

key SalesDocumentType.SalesDocumentType,

 

@Search.defaultSearchElement: true

@UI.hidden: true

SalesDocumentType._SalesDocumentTypeLangDepdnt[1:Language=$session.system_language].SalesDocumentTypeLangDepdnt,

 

//Association

_Text

}

where ( SalesDocumentType.SDDocumentCategory = 'C' or    --> Order

SalesDocumentType.SDDocumentCategory = 'I' or    --> Order w/o charge

SalesDocumentType.SDDocumentCategory = 'L' )
AndreaUS
Product and Topic Expert
Product and Topic Expert
Hi Carlin,

 

the WHERE clause cannot be extended using EXTEND VIEW. Here's the documentation which lists all available syntax additions of EXTEND VIEW.

I recommend you to create another view (wrapper view) that selects from I_SalesDocumentType and that adds one more condition to the WHERE clause.

Hope this helps.

Best

Andrea
carlin_willams
Participant
0 Kudos

Thank you for your swift response.

I can create another custom View (Z), but how can we replace (extend) this ZView in another Consumption stanadard View which is reffred the stanadrd Fiori application/Odata Services.

Please help.

Thanks , carlin

 

AndreaUS
Product and Topic Expert
Product and Topic Expert
Hi Carlin,

sorry, extensions of the WHERE clause are not possible and I cannot offer any simple solution to this issue.

Best

Andrea
carlin_willams
Participant
0 Kudos

Hi Andrea,

I am so sorry , may be i miss communicated to you.

I will create new Z CDS View , in this view i will modify where condition.

How i can change reference(C_SlsDocFlfmtSlsDocTypeVH) with ZCDS View which i have created in standard Consumption View: C_SlsDocFlfllmntAnalyzer.

Below code is stanadard Consumption View: C_SlsDocFlfllmntAnalyzer , need to replace C_SlsDocFlfmtSlsDocTypeVH with Z View

@Consumption.valueHelpDefinition: [{entity: {name: 'C_SlsDocFlfmtSlsDocTypeVH', element: 'SalesDocumentType'} }]
SalesDocument.SalesDocumentType,

 

Please guide.

I've searched in forums but no luck.

Thanks, Carlin

 

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Carlin,

I have checked with the dev team, but I'm so sorry I still cannot offer any solution.

A wrapper view is useful only for your own application. But if we're talking about a standard SAP Fiori app, it is to my knowledge not possible to replace an existing reference with a ZCDS view.

To ensure upgrade stability, only certain stable extension points can be extended or modified. The WHERE clause can't be extended or modified in a stable fashion. And the reference to a view also can't be modified, to my knowledge.

Best

Andrea
vishal006
Explorer
0 Kudos
Hi Andrea,

I have a requirement to add few custom fields to a standard fiori app- "Gross Margin - Presumed/Actual (F3417) "
For this I am trying to extend CDS view - P_GrossMarginUnion, this cds contains union
and I am not able to extend it. I tried following some blogs on how to extend cds with union but no luck.
can you please guide me on how to achieve this? or maybe if you have any example of cds extension with union would be great

Thanks,
Vishal
AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Vishal,

A prerequisite for extending UNION views is the annotation

@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST,#UNION]. Value #UNION is mandatory. Does the CDS view you want to extend have this annotation?

If yes, just make sure to add the new fields to all SELECT statements which are combined with UNION.

This is also described in our docu: EXTEND VIEW (Addition 2)

Example: demo_cds_extend_union extends demo_cds_union

BR

Andrea

vishal006
Explorer
0 Kudos
Hi Andrea,

The standard view which I am trying to extend does not have this annotation @AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST,#UNION].


But the link you mentioned has an example wherein the cds view does not have the annotation and yet its been extended,



So now I am confused, does the standard CDS view needs to have that annotation or we need to give the annotation while extending the CDS view?

Thanks,
Vishal

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Vishal,

the standard view which you want to extend needs this annotation. It is a prerequistie and it is mandatory.

The example does have this annotation.

The screenshot you highlighted shows the  extension, not the extended view.

Here's the extended view (it has the annotation):

Seems like your standard CDS view cannot be extended.

vishal006
Explorer
0 Kudos
Hi Andrea,

Thanks for the quick reply 🙂

Yes, I got it now. Thanks for clearing that up.
Looks like I will have to find some other solution for extending my CDS view.

BR

Vishal
manbhalang_kharpuri
Discoverer
0 Kudos

Hi Andrea,

I am tyring to extend the view - C_BusinessPartnerGovTP , but keep getting the error -

Field selection of association <aliasname> is not supported in Projection Views

Are there limitations on extending?

Here are the views

Thanks,

Mann.

 

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Mann,

this is a limitation that applies to CDS projection views in general. It is not a limitation in extensions.

In CDS projection views, you can define and expose new associations, but you must not select fields from local associations. _Assoc.field is not supported in a projection view, and not in a projection view extension either.

You can select fields from associations that were defined in the underlying projected view, but not from local associations.

This is described in the ABAP Keyword Docu:

"newly defined associations can only be exposed, but they cannot be used in path expressions to include elements from the association target.


The purpose of defining new associations is to model new relationships which can be interpreted by consumer frameworks, such as the RAP query engine. However, no additional joins should be generated on CDS level by denormalizing fields from new association targets into the CDS projection view

[...]


Usage

  • No fields must be selected from locally defined associations. Path expressions are not supported."




Best

Andrea
DPriyanka
Explorer
0 Kudos

Hi Andrea,

I have a requirement to change the default Currency value from EUR to GBP and the currency field is used a parameter in the standard CDS view.

How can I extend this standard CDS view to accommodate the default value change?

Thanks, Priyanka.

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi,

have you tried the currency conversion function CURRENCY_CONVERSION? https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abencds_conv_func_uni...

 
0 Kudos
Hello Andrea.... If I need to add annotations to a standard CDS view and also add a few additional fields to the same standard CDS view, can I do both in same extension view? or do I need to create a separate Metadata Extension for annotations and View Extension for fields?
AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi,

docu: CDS DDL - EXTEND VIEW ENTITY

"In a view entity extension, header annotations are not supported. That means that no annotations are allowed in front of the statement EXTEND VIEW ENTITY."

You can define new fields + field extensions in a view extension.

If you need new header annotations, you need a metadata extension for that.

Does that answer the question?
carlin_willams
Participant
0 Kudos
Hi Andrea Schlotthauer

Greetings!

I want to add new column to standard Fiori Monitor Purchase Order Items (F2358), Application Type
Analytical (SAP Fiori elements) , This Fiori app is based on CDS Views.

I have analyzed the new field is not part of app Consumption/Projection Views ( 2 level Views from Top).
The field is part of Interface View but field is not available in above 2 level consumption Views.

I have searched this specific issue in SAP Commununity and google didn't find any specific information.

Can you please help on this. Appreciate if you the detailed steps how to add new column to standard Fiori Monitor Purchase Order Items (F2358).

I've tried with adptability/extensibility feature no scope to add the field since it is NOT there in consumption views.

Thanks
CW
AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi CW,

thanks for your question.

The Fiori Monitor Purchase Order Items app is based on an RDS-OData service and it is not supported by developer extensibility, unfortunately.

The app is enabled for key user extensibility. However, to use a standard field from the view stack in the service, you need data source extensions. The app is unfortunately not enabled for data source extensions.

Please make a request on influence.sap.com for data source extensions for this particular app.

Best

Andrea

 
arieffaiffmann
Explorer
0 Kudos

Thank you for the informative write up Andrea.

I have a requirement to extend a standard CDS C_Purchaseorderitemacctmntr which is used by Fiori app: Purchase Order Items by Account Assignment (F2420). I need to bring more standard fields from the associated CDS views that's not projected in this view.

Is it a prerequisite that the CDS that I want to extend has to be in Released state because it's not marked for released. Next, the annotation @AbapCatalog.extensibility.extensible: true is not stated explicitly in the CDS, but does that mean it can be extended by default despite the CDS is in non released state?

If that's the case, how can this be achieved using Developer Extensibility because I believe this can't be done via Key User Extensibility. Correct me if I am wrong. Thus, what's your recommendation to fulfil this "simple" requirement?

Best Regards,

 

AndreaUS
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi,

the view C_Purchaseorderitemacctmntr is not released for developer extensibility and also not for key user extensibility.

Please file a request for release on influence.sap.com.

Best regards

Andrea
carlin_willams
Participant
0 Kudos

Thank you very much Andrea for your response.

How to identify app is supported by developer extensibility and Key User extensibility.

I have been trying to check influence.sap.com unfortunately there is NO S/4HANA on Premise  or Fiori Applications options in Project Dropdown while raising a request with influence.sap.com...Not sure which option to choose for this particular request in influence.sap.com.

Also could you please guide me steps for develop this usecase.  I have been searching for the help for this particular there is no help.

Appreciated for all your help.

Thanks

CW

 

Labels in this area