Skip to main content

Module 20: Advanced CDS Views

Advanced CDS views build on CDS fundamentals and introduce analytics, consumption, authorization, and database-side extensibility.
This module explains how CDS becomes the central data model for reporting, Fiori, and RAP.


1. Analytical CDS Views​

What is an Analytical CDS View?​

Analytical CDS views are designed for:

  • Reporting
  • Aggregations
  • KPIs
  • Analytical engines (Embedded Analytics)

They leverage HANA’s OLAP capabilities.


1.1 Analytical Annotations​

@Analytics.dataCategory: #CUBE
@Analytics.query: true
define view Z_CDS_SalesCube
as select from zsales
{
key company,
key year,
SUM( amount ) as total_amount
}
group by company, year

Data Categories​

CategoryMeaning
#DIMENSIONMaster data
#CUBEFact / transactional data
#QUERYAnalytical query
Analytics Layering
  • Cube → Aggregated data

  • Query → End-user consumption

2. Consumption CDS Views​

What is a Consumption View?

Consumption views sit at the top of the CDS hierarchy and are used by:

  • Fiori apps

  • OData services

  • RAP BO projections

They are UI-oriented, not DB-oriented.

2.1 Consumption View Example​

@VDM.viewType: #CONSUMPTION
@EndUserText.label: 'Sales Overview'
@OData.publish: true
define view Z_CDS_SalesCons
as select from Z_CDS_SalesCube
{
company,
year,
total_amount
}
Design Rule

Consumption views should contain no complex logic — only projection and UI annotations.

3. Authorization Checks in CDS​

CDS supports data-level authorization.

3.1 Authorization Annotation​

@AccessControl.authorizationCheck: #CHECK
define view Z_CDS_SecureSales
as select from zsales
{
company,
amount
}

3.2 DCL (Data Control Language)​

Authorization logic is defined separately using DCL.

define role Z_SALES_AUTH {
grant select on Z_CDS_SecureSales
where company = aspect pfcg_auth( 'Z_COMP', 'ACTVT' );
}
Why CDS Authorization Matters
  • Centralized

  • DB-level filtering

  • Automatically applied to OData & RAP

4. CDS Table Functions​

What is a CDS Table Function?

A CDS table function:

  • Returns a table

  • Is implemented using AMDP (SQLScript)

  • Enables complex DB-side logic

4.1 CDS Table Function Definition​

define table function Z_TF_SalesAgg
returns {
company : bukrs;
total : abap.curr(15,2);
}
implemented by method
zcl_sales_amdp=>get_data;

4.2 AMDP Implementation (Preview)​

METHOD get_data
BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY.

RETURN
SELECT company,
SUM(amount) AS total
FROM zsales
GROUP BY company;

ENDMETHOD.
When to Use Table Functions
  • Logic not possible in CDS

  • Complex calculations

  • Procedural DB logic

5. CDS vs AMDP (Very Important)​

AspectCDSAMDP
NatureDeclarativeProcedural
LanguageCDS DDLSQLScript
PortabilityHighLow (HANA-only)
ComplexityMediumHigh
Use Case80–90% scenariosEdge cases
SAP Recommendation

Use CDS first. Use AMDP only when CDS is not sufficient.

6. Layered CDS Architecture (Best Practice)​

Basic CDS (Tables)
↓
Composite CDS (Joins / Associations)
↓
Analytical CDS (Cubes / Queries)
↓
Consumption CDS (UI / OData / RAP)
Interview Gold

Mention CDS layering to demonstrate architectural maturity.

7. Common Mistakes​

Avoid These
  • Putting business logic in consumption views

  • Overusing AMDP

  • Skipping authorization annotations

  • Creating monolithic CDS views

  • Treating CDS like Open SQL

8. Summary​

  • Analytical CDS enables reporting & KPIs

  • Consumption views serve UI & RAP

  • CDS authorizations enforce data security

  • Table functions handle complex DB logic

  • CDS is preferred over AMDP

  • Layered CDS design is critical

9. Practice Exercises​

  • Create an analytical cube CDS.

  • Build a consumption view on top.

  • Add CDS authorization with DCL.

  • Implement a CDS table function.

  • Decide CDS vs AMDP for a scenario.

10. What’s Next?​

➡️ Module 21: AMDP (ABAP Managed Database Procedures)

Learning Tip

Advanced CDS knowledge separates developers from architects.