SAP CDS examples
These CDS examples show Core Data Services views, the modern SAP modeling layer, with joins, associations, aggregation and annotations that expose data to Fiori and analytics.
Two CDS examples: a view entity over VBAK with a 1..n association to VBAP exposing the items alongside the header, and a cube over I_SalesOrderItem with @Analytics.dataCategory, @OData.publish and @Aggregation.default annotations. The point is that annotations turn one model into an OData service, an analytical cube or UI metadata; layer base and composite views and push aggregation down.
- Watch out: Ignoring annotations that unlock OData/analytics.
- Worked examples: a cds view with an association, aggregation and annotations, what it teaches.
- How CDS examples fits into SAP development and the wider SAP landscape
A CDS view with an association
define view entity Z_SalesDoc as select from vbak
association [1..*] to vbap as _Item on vbak.vbeln = vbap.vbeln
{
key vbak.vbeln,
vbak.kunnr,
_Item
}Aggregation and annotations
@Analytics.dataCategory: #CUBE
@OData.publish: true
define view entity Z_Sales_Cube as select from I_SalesOrderItem {
key SoldToParty,
@Aggregation.default: #SUM
NetAmount
}What it teaches
CDS models data close to the database with reusable, annotated views. Annotations turn a view into an OData service, an analytical cube, or UI metadata, one model, many uses. Layer base and composite views, and push filtering/aggregation down for performance.
Common pitfalls
- Ignoring annotations that unlock OData/analytics.
- Monolithic views.
- Late aggregation hurting performance.