Core Data Services (CDS) ABAP

Extending CDS Views

Introduction

Motivation

In both SAP standard and partner solutions, the following scenarios occur frequently:

  • A field exists in the table but not in the view being used
  • A field from an append structure needs to be added to a view
  • A view must be extended with a field from another table

Wrong Solution

  • Modifying the view
  • Copying the view

Correct Solution

  • Modification-free enhancement using View Extends

Creating a CDS View Extend

Syntax

@AbapCatalog.internal.setChange: 'FLDADD_NO_ASS_INFLUENCE'
@AbapCatalog.sqlViewAppendName: 'YC4121EE76312A77'

extend view I_CENTRALPURCHASECONTRACTTP with YB763H63UQWBLTS7PVUOBPFZFZU

{ 
  _CntrlPurchaseContractExten.YMM_DISTR_EXECUTED_PDH as YMM_DISTR_EXECUTED_PDH
}

More complex example

@AbapCatalog.sqlViewAppendName: 'YMM_E_CCTRHEKBED'

extend view C_CentralPurchaseContractTP with YMM_E_CntrlPurchContrEkBed
  association [0..1] to YMM_C_PM_EkBed as _Ekbed 
      on _Ekbed.Ekbed = I_CentralPurchaseContractTP.yy_mm_ekbed_pdh
{
  @ObjectModel.readOnly: true
  _Ekbed.Description as EkBedText
}

Additional Information

  • How to recognize that a view has been extended?
    Screenshot showing how Eclipse indicates extensions

  • What happens if the added field is later delivered in the SAP standard?

Restrictions on Extensibility

It is possible to restrict extensibility to specific data sources.
SAP often uses this to enforce the use of Extension Includes.

@AbapCatalog.extensibility: { 
                              allowNewDatasources: false,
                              DataSources: [<list of tables and/or associations>]
}

E_-Views (Extension Includes)

alt text

CDS Metadata Extensions (MDE)

With Metadata Extensions, annotations can:

  1. Be stored separately from the CDS view, and
  2. Be added later.

This is quite useful, especially for large views.

The downside of Metadata Extensions is reduced clarity.
Since Eclipse groups CDS views by file type, it is often not obvious that an MDE exists for a view.
If additional annotations are added inside the view, they may not have the expected effect.

The same issue applies to authorization checks.