Module 19: CDS Views – Fundamentals
Core Data Services (CDS) is SAP’s strategic data modeling layer on top of the database.
CDS is not just about performance — it defines what the data means, not just how it is selected.
1. What is CDS?
Definition
CDS (Core Data Services) is a declarative data definition language used to define semantically rich data models directly on the database.
Why CDS Exists
Traditional Open SQL:
- Retrieves data
- Has no semantics
- Limited reuse
CDS:
- Defines data + meaning
- Enables code pushdown
- Reusable across ABAP, OData, analytics
- Authorization-aware
In S/4HANA, CDS is the default data access layer.
2. Where CDS Fits in the Architecture
Database (HANA) ↑ CDS Views (Semantic Layer) ↑ ABAP / OData / RAP / Analytics
Think of CDS as ABAP Dictionary + Open SQL + semantics combined.
3. Basic CDS Syntax
A CDS view is defined using DDL Source in ADT (Eclipse).
3.1 Basic CDS View Example
@AbapCatalog.sqlViewName: 'ZV_FLIGHT'
@EndUserText.label: 'Flight Data'
define view Z_CDS_Flight
as select from spfli
{
key carrid,
key connid,
cityfrom,
cityto
}
Key Elements
-
define view
-
select from
-
Field list
-
Keys
-
CDS view name → Z_CDS_*
-
SQL view name → 16 characters, uppercase
4. Annotations (Very Important)
Annotations add metadata and semantics to CDS views.
4.1 Common Annotations
@EndUserText.label: 'Airline'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
Categories of Annotations
-
UI annotations
-
Analytics annotations
-
Authorization annotations
-
Catalog annotations
Annotations drive:
-
Fiori UI behavior
-
Analytics
-
Authorization
-
OData exposure
5. Associations vs Joins
5.1 Joins (Classic SQL Style)
define view Z_CDS_FlightJoin
as select from spfli
inner join scarr
on spfli.carrid = scarr.carrid
{
spfli.carrid,
spfli.connid,
scarr.carrname
}
5.2 Associations (CDS Way – Recommended)
define view Z_CDS_FlightAssoc
as select from spfli
association [0..1] to scarr as _Carrier
on $projection.carrid = _Carrier.carrid
{
key carrid,
key connid,
_Carrier.carrname
}
Why Associations Are Better
| Aspect | Join | Association |
|---|---|---|
| Eager loading | Yes | No |
| Reuse | Low | High |
| Semantics | Low | High |
| Performance | OK | Better (lazy) |
Prefer associations over joins unless eager data is required.
6. Parameterized CDS Views
Parameterized CDS views accept input parameters.
Example
define view Z_CDS_Flight_Param
with parameters
p_carrid : spfli.carrid
as select from spfli
{
key carrid,
key connid,
cityfrom,
cityto
}
where carrid = :p_carrid
Usage in ABAP:
SELECT * FROM Z_CDS_Flight_Param( p_carrid = @lv_carrid )
INTO TABLE @DATA(lt_flights).
Parameterized CDS replaces many dynamic WHERE conditions.
- CDS vs Open SQL (When to Use What)
| Scenario | Recommendation |
|---|---|
| Reusable data model | CDS |
| Analytics / Reporting | CDS |
| One-off simple SELECT | Open SQL |
| OData / RAP | CDS |
| Complex DB logic | CDS / AMDP |
8. Common Beginner Mistakes
-
Treating CDS like a simple SELECT
-
Overusing joins instead of associations
-
Missing authorization annotations
-
Hard-coding logic better suited for CDS
-
Creating very large monolithic CDS views
9. Summary
-
CDS is SAP’s semantic data model
-
Defined using DDL in Eclipse
-
Annotations add meaning and behavior
-
Associations are preferred over joins
-
Parameterized CDS adds flexibility
-
CDS is reusable across layers
10. Practice Exercises
-
Create a basic CDS view on a database table.
-
Add meaningful annotations.
-
Replace a JOIN with an association.
-
Create a parameterized CDS view.
-
Consume CDS view in ABAP SELECT.
11. What’s Next?
➡️ Module 20: Advanced CDS Views
If you understand CDS fundamentals well, RAP and analytics become much easier.