Chapter 16 · Modern ABAP
CDS Views — Modern Data Modeling
How to define reusable, semantic data models in ABAP that push logic to HANA and power RAP, Fiori, and OData services.
Up to now, you have been reading from tables directly. SELECT from VBAK, SELECT from KNA1, join, process, display. That works — for reports. But modern SAP development does not work that way.
In S/4HANA, RAP, Fiori, and OData, data is not read from tables. It is read from CDS Views — Core Data Services Views. These are semantic data models that live in the database, describe business meaning, and can be consumed by both ABAP code and external systems like Fiori apps.
This is the chapter where you cross from classic ABAP into the modern world. From here on, everything you build — RAP business objects, Fiori apps, analytics — sits on top of CDS Views.
🎯 What You Will Learn in This Chapter
- What CDS Views are and why they matter in S/4HANA
- The difference between CDS Views and SE11 Views
- How to create a CDS View in Eclipse ADT
- The main annotation families and what they control
- What Associations are and how they differ from JOINs
- How to create Parameterized CDS Views
- What Access Control (DCL) is and how it enforces row-level security
- How to consume CDS Views in ABAP with Open SQL
- The difference between classic CDS View and modern CDS View Entity
📘 What is a CDS View?
CDS stands for Core Data Services. A CDS View is a data model definition written in SQL-like syntax that is compiled and executed directly on the SAP HANA database.
Think of it as a supercharged SQL view. It does everything a normal view does — selects, joins, filters — but adds:
- Calculations — arithmetic, string operations, case expressions
- Aggregations — SUM, AVG, COUNT, MIN, MAX
- Annotations — metadata that controls authorization, UI rendering, OData exposure
- Associations — declared relationships to other views
- Parameters — input values that filter the result at query time
- Semantics — built-in meaning for amounts, currencies, units, dates
⚖️ CDS View vs SE11 View — Why the Change?
You already learned about SE11 Views in Chapter 5. Why do we need something else?
| Feature | SE11 View | CDS View |
|---|---|---|
| Where defined | SE11 (Data Dictionary) | Eclipse ADT |
| Syntax | Graphical (no code) | SQL-like code |
| Calculations | No | Yes |
| Aggregations | No | Yes |
| Associations | No (only JOINs) | Yes |
| Parameters | No | Yes |
| Annotations | No | Yes |
| Row-level auth (DCL) | No | Yes |
| Pushes logic to HANA | Partial | Full |
| Consumable by RAP / Fiori | No | Yes |
| Modern standard | Legacy | ✅ Standard |
🛠 Creating Your First CDS View
CDS Views are created in Eclipse ADT, not in SAP GUI.
In Eclipse ADT, right-click your package. Choose New → Other ABAP Repository Object → Core Data Services → Data Definition.
Use the naming convention: ZI_ for interface views, ZC_ for consumption views. Example: ZI_TRAVEL. Description: “Travel interface view”.
Select “Define View” (classic syntax) or “Define View Entity” (modern). For S/4HANA 2020+, prefer Define View Entity.
Fill in the template with your data source, fields, and annotations.
A minimal CDS View
@AbapCatalog.sqlViewName: 'ZITRAVEL'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Travel Interface View'
define view ZI_Travel
as select from /dmo/travel as Travel
{
key Travel.travel_id as TravelId,
Travel.agency_id as AgencyId,
Travel.customer_id as CustomerId,
Travel.begin_date as BeginDate,
Travel.end_date as EndDate,
Travel.booking_fee as BookingFee,
Travel.total_price as TotalPrice,
Travel.currency_code as CurrencyCode,
Travel.status as Status
}
A modern CDS View Entity (ABAP 7.55+)
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Travel Interface View'
define view entity ZI_Travel
as select from /dmo/travel as Travel
{
key Travel.travel_id as TravelId,
Travel.agency_id as AgencyId,
Travel.customer_id as CustomerId,
Travel.begin_date as BeginDate,
Travel.end_date as EndDate,
Travel.booking_fee as BookingFee,
Travel.total_price as TotalPrice,
Travel.currency_code as CurrencyCode,
Travel.status as Status
}
define view needs a separate SQL view name via @AbapCatalog.sqlViewName. The modern define view entity does not — it maps directly to the database. In ABAP Cloud and S/4HANA 2020+, always use define view entity.
🏷️ Annotations — The Metadata Layer
Annotations are declarations prefixed with @ that add meaning and behavior to a CDS View. They are what turns a plain data model into a semantic, service-ready definition.
The main annotation families
| Annotation | What It Controls | Example |
|---|---|---|
@AbapCatalog | Technical properties (SQL view name, buffering) | @AbapCatalog.sqlViewName: 'ZI...' |
@AccessControl | Authorization behavior (DCL checks) | @AccessControl.authorizationCheck: #CHECK |
@EndUserText | Labels for fields and views | @EndUserText.label: 'Travel ID' |
@Semantics | Meaning of fields (amounts, currencies, dates) | @Semantics.amount.currencyCode: 'CurrencyCode' |
@UI | UI rendering in Fiori (lineItem, selectionField, identification) | @UI.lineItem: [{ position: 10 }] |
@OData | OData service publishing | @OData.publish: true |
@Analytics | Analytical queries and dimensions | @Analytics.dataCategory: #CUBE |
@Search | Search behavior (fuzzy search, ranking) | @Search.searchable: true |
Practical example — a consumption view
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Travel Consumption View'
@UI.headerInfo: { typeName: 'Travel', typeNamePlural: 'Travels' }
@Metadata.allowExtensions: true
define view entity ZC_Travel
as select from ZI_Travel
{
@UI.lineItem: [{ position: 10 }]
@UI.identification: [{ position: 10 }]
key TravelId,
@UI.lineItem: [{ position: 20 }]
@UI.selectionField: [{ position: 20 }]
AgencyId,
@UI.lineItem: [{ position: 30 }]
CustomerId,
@UI.lineItem: [{ position: 40 }]
BeginDate,
@UI.lineItem: [{ position: 50 }]
EndDate,
@UI.lineItem: [{ position: 60 }]
@Semantics.amount.currencyCode: 'CurrencyCode'
TotalPrice,
@Semantics.currencyCode: true
CurrencyCode
}
🔗 Associations — Lazy Joins
An Association is a declared relationship between two CDS Views or between a CDS View and a table. It is like a JOIN — but better.
JOIN vs Association
| Aspect | JOIN | Association |
|---|---|---|
| When executed | Immediately | Only when used |
| Data volume | Full merge of all rows | Only the rows requested |
| Declaration | In the SELECT clause | In the view definition |
| Reusability | Per query | Per view — reused everywhere |
| Navigation | No | Yes (path expressions) |
| Used by RAP / OData | No | Yes |
Defining an Association
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Travel with Customer'
define view entity ZI_TravelWithCustomer
as select from /dmo/travel as Travel
association [0..1] to /dmo/customer as _Customer
on Travel.customer_id = _Customer.customer_id
{
key Travel.travel_id as TravelId,
Travel.customer_id as CustomerId,
Travel.total_price as TotalPrice,
// Expose the association
_Customer
}
Using the Association in a path expression
@EndUserText.label: 'Travel with customer name'
define view entity ZI_TravelWithName
as select from ZI_TravelWithCustomer
{
key TravelId,
CustomerId,
// Path expression — navigates the association
_Customer.first_name as CustomerFirstName,
_Customer.last_name as CustomerLastName,
TotalPrice
}
🎛️ Parameterized CDS Views
A CDS View can accept input parameters that are supplied at query time. This lets one view serve many scenarios — different dates, currencies, or scopes — without duplicating the model.
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Travel by date range'
define view entity ZI_TravelByDate
with parameters
P_FromDate : abap.dats,
P_ToDate : abap.dats
as select from /dmo/travel as Travel
{
key Travel.travel_id as TravelId,
Travel.customer_id as CustomerId,
Travel.begin_date as BeginDate,
Travel.end_date as EndDate
}
where Travel.begin_date >= :P_FromDate
and Travel.end_date <= :P_ToDate
🔒 Access Control (DCL) — Row-Level Security
A CDS View can be protected by a DCL (Data Control Language) file that defines row-level authorization. This means different users see different rows of the same view, based on their authorization roles.
The annotation that turns it on
@AccessControl.authorizationCheck: #CHECK
A simple DCL file
@EndUserText.label: 'Authorization for ZI_Travel'
@MappingRole: true
define role ZI_Travel {
grant select on ZI_Travel
where ( Travel.agency_id ) =
aspect pfcg_auth ( S_AGENCY, ACTVT = '03' );
}
What this means: a user only sees rows where the agency_id matches what they are authorized for in their role (transaction PFCG).
AUTHORITY-CHECK statements. With DCL, authorization is defined once at the data layer. Every consumer — ABAP, RAP, Fiori, OData — gets the same enforcement automatically.
📥 Consuming CDS Views in ABAP
Once a CDS View is created and activated, you consume it in ABAP just like a table:
" Read from a CDS View like a table
SELECT * FROM ZI_Travel
INTO TABLE @DATA(lt_travel)
WHERE CustomerId = @lv_customer_id.
LOOP AT lt_travel INTO DATA(ls_travel).
WRITE: / ls_travel-TravelId, ls_travel-TotalPrice.
ENDLOOP.
" For parameterized views, use a WITH clause
SELECT * FROM ZI_TravelByDate(
P_FromDate = @lv_from,
P_ToDate = @lv_to
) INTO TABLE @DATA(lt_travel_range).
📝 Chapter Summary
- CDS Views are semantic data models defined in ABAP and executed on the HANA database.
- They replace SE11 Views for modern development — supporting calculations, annotations, associations, parameters, and DCL.
- Two syntaxes: define view (classic) and define view entity (modern, recommended).
- Annotations add meaning and behavior:
@AccessControl,@UI,@Semantics,@OData, etc. - Associations are lazy joins — declared once, executed only when used via path expressions.
- Parameters make views reusable across scenarios.
- DCL enforces row-level authorization once, for all consumers.
- Consume CDS Views in ABAP with
SELECT ... FROM ZI_..., just like a table. - Everything modern — RAP, Fiori, OData, Analytics — sits on top of CDS Views.
🎤 Interview Questions & Answers
CDS Views are the single most-tested modern ABAP topic. Almost every S/4HANA or cloud project interview will include these questions.
A CDS View (Core Data Services View) is a data model definition written in SQL-like syntax that runs directly on the SAP HANA database. It combines tables, joins, calculations, and annotations in a single declarative definition. CDS Views push logic down to the database and expose semantically rich data models for RAP, Fiori, and OData services.
SE11 views (Database Views, Projection Views, Maintenance Views, Help Views) are classic SAP views created in the Data Dictionary. They are limited to joins and projections, cannot include calculations or annotations, and are not optimized for HANA. CDS Views support calculations, aggregations, associations, annotations, parameters, and Code Pushdown, and they are the modern standard for S/4HANA.
Annotations are metadata declarations prefixed with @ that add behavior and semantics to a CDS View. Examples: @AccessControl.authorizationCheck, @EndUserText.label, @UI.lineItem, @Semantics.amount.currencyCode. Annotations control authorization, semantics, UI rendering, OData exposure, and more.
An Association is a predefined relationship between two CDS Views or between a CDS View and a table. Unlike a JOIN, an Association is not executed at runtime unless it is exposed or used in a path expression. Associations enable lazy loading, reduce data volume, and are used by RAP and OData to navigate between entities.
A JOIN combines data from two sources immediately and returns a merged result set. An Association defines a relationship between two sources but does not execute until the association is used in a path expression or exposed for navigation. Associations are more performant because the join is only performed when needed.
Common CDS View types: Basic Interface View (data foundation), Composite Interface View (business logic), Consumption View (UI, OData, Analytics), and View Entity (in ABAP Cloud via ADT). Each type has a specific purpose — interface views focus on reusable semantics, consumption views focus on end-user scenarios.
A Parameterized CDS View accepts input parameters that are supplied when the view is queried. Parameters are declared using a colon syntax (e.g., P_DATE : abap.dats). They allow filtering at query time without changing the view definition, and are commonly used for date-range reports, currency conversions, and dynamic authorizations.
A CDS View is the classic syntax defined using @AbapCatalog.sqlViewName annotation, which requires a separate SQL view in the database. A CDS View Entity is the modern syntax (introduced in ABAP 7.55) that maps directly to the database without a separate SQL view. View Entities are the recommended syntax in ABAP Cloud and S/4HANA 2020+.
The @AccessControl annotation family defines how authorization is enforced when a CDS View is queried. @AccessControl.authorizationCheck controls whether the view requires an access control definition, and DCL (Data Control Language) files provide row-level authorization logic. This ensures users only see the data they are authorized to see.
You consume a CDS View in ABAP by using a SELECT statement against the CDS View name (not the SQL view name). For example: SELECT * FROM ZI_MyView INTO TABLE @DATA(lt_result). The CDS View is treated like a database table in ABAP, and the access happens via the ABAP SQL engine, which passes the query to the HANA database optimized.
🛠 Practice Task for This Chapter
Build three CDS Views that chain together. This is the standard pattern for real SAP projects.
- Create a Basic Interface View: Create
ZI_Travelthat reads from/DMO/TRAVELand exposes TravelId, CustomerId, TotalPrice, CurrencyCode, and Status. - Add an Association: Create
ZI_TravelWithCustomerthat includes the fields from ZI_Travel plus an association to/DMO/CUSTOMER. Expose the association. - Create a Consumption View: Create
ZC_Travelthat reads from ZI_TravelWithCustomer, exposes the customer name via the association, and adds@UI.lineItemannotations to make it Fiori-ready. - Preview the data: Right-click each CDS View in ADT and choose Open With → Data Preview. Verify the data appears as expected.
- Consume in ABAP: Write a small ABAP report that selects from ZC_Travel and displays the results in an ALV report.
- Add a Parameter (bonus): Create
ZI_TravelByDatewith parameters P_FromDate and P_ToDate, and filter by date range.
Test: Kon Banega Crorepati?
5 questions. ₹1 Crore. Prove you understood CDS Views. No pressure — restart anytime.
Explore Our Instructor-Led SAP & IT Courses
Self-study works. But if you want guided training, real project practice, and placement support — here are the courses we offer. Book a free demo before you decide.
WhatsApp us