Sub topic 15
Embedded analytics and CDS views
This chapter assumes you know basic relational concepts (tables, keys, joins), have seen the Universal Journal (ACDOCA) and the sales tables VBAK and VBAP, and understand that Fiori is the user interface layer. It covers how S/4HANA reports on live transactional data through CDS views.
What embedded analytics means
Embedded analytics means the reporting runs inside the S/4HANA system, on the same HANA database that holds the transactions. There is no nightly copy into a separate warehouse for operational reports. A posting in Finance or a new sales order is visible to a report as soon as it is saved.
The building block is the Core Data Services (CDS) view. A CDS view is a view defined in a SAP data definition language. The database runs it as a normal SQL view. It can also carry annotations, which are metadata that tell other layers how to use it.
Layers of CDS views
SAP delivers its views in layers. Each layer reads the one below it.
- Basic interface views map tables to business names and expose keys and associations.
- Composite views join and aggregate basic views, for example sales order items with customers.
- Consumption views are shaped for one app or query and carry the UI and analytical annotations.
A small example
This view reads the Universal Journal and totals amounts per company code and G/L account. Run it in ABAP Development Tools in Eclipse.
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Balance per G/L account'
define view entity ZI_GLBalance
as select from acdoca
{
key rbukrs as CompanyCode,
key racct as GLAccount,
key gjahr as FiscalYear,
rhcur as CompanyCodeCurrency,
@Semantics.amount.currencyCode: 'CompanyCodeCurrency'
sum( hsl ) as BalanceInCompanyCodeCurrency
}
where rldnr = '0L'
group by rbukrs, racct, gjahr, rhcurSetting authorizationCheck to #NOT_REQUIRED keeps the example short. In a real system, productive views should use a data control (a CDS access control object) so users see only the company codes they are authorized for.
Using the view
Because the view is a database object, ABAP can select from it like a table.
SELECT CompanyCode, GLAccount, BalanceInCompanyCodeCurrency
FROM zi_glbalance
WHERE CompanyCode = '1010'
AND FiscalYear = '2024'
INTO TABLE @DATA(balances).Fiori apps, analytical queries, and OData services consume the same view. One definition therefore serves every channel.
Common errors
- Querying raw tables in new code. SAP can change table structures between releases, while released CDS views are a stable contract.
- Skipping access control. A view without a data control can expose data across company codes.
- Missing currency or unit annotations. Amount fields without a
@Semantics.amount.currencyCodelink cannot be summed or displayed correctly. - Building on unreleased SAP views. They can change without notice and break upgrades, which conflicts with the clean core approach in the next chapter.
Exercise
Why is a consumption view usually a better source for a Fiori report than the underlying table ACDOCA?
Show answer
The consumption view uses business names, has annotations for the UI and analytics, and applies access control. It is also a released, stable interface, while table structures can change between releases.