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: 

Co-Authored: Ritesh K Kumaria, Shekhar Razdan

In continuation to the previous Post (The Semantically Rich Data Model – An ABAP based CDS Views example)

Annexure 3: How to Extend CDS views


CDS Extensions are ABAP dictionary object defined in the <DDL: Data Definition Language> of ABAP Core data services and is used to add fields of the entities used by a CDS View to a view without making modifications.


  1. Extension of a Standard CDS View.

  • The example uses Standard CDS View demo_cds_original_view that exists in the Package SABAPDEMOS to demonstrate the concept. Two new fields are added via Extension.
  • Add package SABAPDEMOS under your Favorites Package, using right click and Add package.


  • Enter the Name of the package “SABAPDEMOS” and press OK.

  • Package SABAPDEMOS is added under the Favorites Packages.

  • In this exercise, an extension would be carried out on the standard CDS view demo_cds_original_view.
  • The source code for demo_cds_original_view is as given in the below screen shot.

  • The symbol means that an extension already exists for the CDS view demo_cds_original_view. We will create another extension on the same CDS view demo_cds_original_view and it would also be visible under the “Extended With” section.

  • Right Click on the Package under the Project node, then select “Other ABAP Repository Object” and in the search bar fill in DDL.

  • Click on the DDL source and create a view fill in the name and description and save it in a Package and activate the same.

  Take the template of Extend View and press Finish.

  • Code for creating an Extension view. Fields “airpfrom” and “airpto” are the fields being added to the original view via extension.


The extended fields (Origin_Airport & Disembarkation) are visible on the output by pressing F8 on demo_cds_original_view.



  • The newextension is visible on the parent CDS view demo_cds_original_view as well.



2. Extension using the $EXTENSION.*

Another way of extending the CDS view through use of $EXTENSION.*. This is in a way, similar to customizing includes in ABAP tables, where a place holder to add new fields is already provided in Standard SAP tables.

  • Right Click on the Package under the Project node, then select “Other ABAP Repository Object” and in the search bar fill in DDL.


  • Click on the DDL source and create a view fill in the name and description and save it in a Package and activate the same. Here any extension done on the Database tables SNWD_BPA and SNWD_SO, would result in addition of those fields in the final field list of the VIEW sales_order11.


  • An extension was done on SNWD_BPA, only after the CDS view Sales_order11 was activated.


  • The field was visible in the final list as below :

  • Note: The above approach cannot be used in the following cases :

- If the CDS view is a union set created using union.

- If aggregate (MAX, MIN, AVG, SUM, and COUNT) expressions are used.

3. Extension concept via Extension as an Association (VDM)


The below example is based on views organized based on Virtual Data Model (VDM) principles



Different types of Views:

- BASIC                  : Views that form the core data basis without data redundancies.

- COMPOSITE : Views that provide data derived and/or composed from the BASIC views.

- CONSUMPTION: Views that serve for specific application purposes and may be defined based upon public interface (For example, BASIC and COMPOSITE) views. The Consumption View is not shown in the above hierarchy.

  • Sample code for ZCDS_DEMO_VIEW.

  • Sample code for ZCDS_DEMO_VIEW_2

  • Sample code for ZCDS_EXTENSION_VDM



Create an Append structure to DB tables and Extend the view ZCDS_DEMO_VIEW_2 and ZCDS_EXTENSION_VDM. For example an extension would be performed through the Append “OILVBAP” Field-OID_EXTBOL on VABP.

Views ZCDS_DEMO_VIEW_2 and ZCDS_EXTENSION_VDM have been extended as follows:

Extension for ZCDS_DEMO_VIEW_2

Extension for ZCDS_EXTENSION_VDM

Once the views have been extended and since the view ZCDS_EXTENSION_VDM is linked to ZCDS_DEMO_VIEW_2 via an Association the fields from Extension are added to the field list.

Another option could be at Extend the view ZCDS_EXTENSION_VDM and build another view on top of ZCDS_DEMO_VIEW_2 to include the field.