SAP ABAP CDS View – Extend (Extend a CDS View)

In SAP ABAP CDS views, view extension allows you to enhance an existing CDS view by adding additional fields or modifying annotations, without changing the original view itself. This feature helps maintain the integrity of standard views while enabling customization for specific business needs.


🔹 Syntax for Extending a CDS View

To extend an existing CDS view, we use the EXTEND VIEW keyword.

Basic Syntax of Extending a CDS View

@AbapCatalog.sqlViewName: 'ZFLIGHT_EXT'
@AccessControl.authorizationCheck: #NOT_REQUIRED
extend view ZFLIGHT_CDS with ZFLIGHT_EXT {
additional_field1 as new_field1,
additional_field2 as new_field2
}

Explanation:


🔹 Example of Extending a CDS View with Additional Fields

@AbapCatalog.sqlViewName: 'ZFLIGHT_EXTENDED'
@AccessControl.authorizationCheck: #CHECK
extend view ZFLIGHT_CDS with ZFLIGHT_EXTENDED {
price * 0.9 as discounted_price, -- Applying a 10% discount
'Y' as new_flag -- New field indicating active flights
}

Explanation:


🔹 Extending a CDS View with Associations

extend view ZFLIGHT_CDS with ZFLIGHT_ASSOCIATED {
association [0..1] to scarr as _Carrier on _Carrier.carrid = ZFLIGHT_CDS.carrid
}

Explanation:


🔹 Extending CDS Views with Annotations

@AbapCatalog.sqlViewName: 'ZFLIGHT_ANNOTATED'
@AccessControl.authorizationCheck: #CHECK
extend view ZFLIGHT_CDS with ZFLIGHT_ANNOTATED {
@UI.lineItem: [{ position: 10 }]
price as flight_price
}

Explanation:


🔹 Key Benefits of Extending CDS Views


🔹 When to Use CDS View Extension?