Skip to Content

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.


AddPackage.png

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

PackageName.png

  • Package SABAPDEMOS is added under the Favorites Packages.

FavoritePackage.png

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

DEMO_CDS_ORIGINAL_VIEW.png

  • The symbol ExtensionSymbol.pngmeans 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.

ExtensionWithView.png

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

OtherRepositoryObjects.png

CreateDDL.png

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

WithTemplate.png

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


DemoExtension.png

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


ExtensionOutput.png


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


NewExtensionWith.png


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.

OtherRepositoryObjects.png


SearchDDL.png

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

Sales_Order11.png


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

SNWD_BPA_Append.png


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

Field1_Extension.JPG

  • 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


CustomVDM.JPG


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.

ZCDS_DEMO_VIEW.png

  • Sample code for ZCDS_DEMO_VIEW_2

ZCDS_DEMO_VIEW_2.JPG

  • Sample code for ZCDS_EXTENSION_VDM


ZCDS_EXTENSION_VDM.png


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

ZCDS_DEMO_VIEW_2-New.JPG.png

Extension for ZCDS_EXTENSION_VDM

ZCDS_EXTENSION_VDM-New.png

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.

ExtensionOutput2.png

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.


To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply