Sub topic 1
What embedded analytics is and how it is built
Prerequisites
This chapter assumes you already have the following:
- Basic SQL: SELECT, JOIN, GROUP BY and aggregate functions such as SUM.
- Familiarity with SAP S/4HANA business objects such as sales orders and customers.
- Basic navigation of the SAP Fiori launchpad.
- Awareness of the difference between transactional (OLTP) and analytical (OLAP) workloads.
You do not need to write ABAP CDS code yet. The next chapter introduces CDS view entities. Here you build the working model that the rest of the tutorial relies on.
What embedded analytics means
Embedded analytics is reporting and analysis that runs inside the SAP S/4HANA system, directly on the live transactional data. There is no extract step and no second copy of the data. When a user opens a report, the system reads the same tables that sales, finance and logistics transactions write to.
Two technical facts make this possible:
- SAP HANA is an in-memory, column-oriented database. It can aggregate large volumes of rows fast enough to answer analytical queries on the operational tables.
- ABAP CDS (Core Data Services) views describe the data model in the database layer. Analytical annotations on those views tell the analytical engine which fields are measures, which are dimensions, and how to aggregate.
The result is a model where the analytical definition lives in the same system as the business data. A change to a sales item shows up in the next query run.
How it differs from a separate data warehouse
A data warehouse, such as SAP BW/4HANA or SAP Datasphere, copies data from source systems on a schedule. It stores the copy in its own structures. Embedded analytics skips that copy. The trade-offs are real, so the choice matters.
| Aspect | Embedded analytics | Separate data warehouse |
|---|---|---|
| Data freshness | Live, read at query time | As fresh as the last load |
| Data location | Source tables in S/4HANA | Replicated and stored copy |
| Data sources | The S/4HANA system | Many systems, SAP and non-SAP |
| History and snapshots | Only what the transactional tables keep | Can keep full history independent of the source |
| Load on the operational system | Queries share the system's resources | Queries run on separate resources |
| Typical use | Operational reporting, KPIs, real-time checks | Enterprise reporting, cross-system consolidation, planning |
A practical rule: use embedded analytics when the question is about what is happening now in this system. Use a warehouse when you must combine several systems, keep history the source discards, or protect the operational system from heavy reporting loads. Many landscapes use both.
The building blocks
Embedded analytics is assembled from a small set of parts. Each later chapter in this tutorial covers one of them in detail.
- Database tables. The transactional tables that hold sales items, customers, journal entries and so on.
- CDS view entities. Views defined in ABAP that select from tables or other views and expose fields and associations.
- The Virtual Data Model (VDM). SAP's layered convention for organizing CDS views, from raw data up to views meant for end users.
- Analytical annotations. Metadata on views and fields that assigns a role: cube, dimension, measure, or query.
- Access controls. CDS access control objects (DCL) that restrict rows by user authorization.
- Analytical engine and OData services. The runtime that evaluates a query view, aggregates the data, and exposes the result to front ends.
- Front ends. SAP Fiori apps, KPI tiles, and other tools that call the engine.
The data flow at a glance
The diagram shows how a user request travels through these parts, from the app down to the tables and back.
Read the diagram from top to bottom. The front end never touches tables directly. It calls a service, the service evaluates a query view, and the query view reads a cube that joins dimensions through associations. Access control is applied as part of the CDS read, so the same rules hold regardless of which front end asked.
A first look at the model
You do not need to understand every line yet. The three examples below come from the tutorial's running scenario, in which a hypothetical table zsales_item holds sales items and zcustomer holds customers. Each example shows one layer of the model.
A dimension
A dimension describes the "by what" of an analysis: by customer, by country, by product. It has a key, and often a text and some attributes.
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Customer'
@Analytics.dataCategory: #DIMENSION
define view entity ZI_CustomerDim
as select from zcustomer
{
key customer_id as CustomerId,
@Semantics.text: true
customer_name as CustomerName,
country as Country
}The annotation @Analytics.dataCategory: #DIMENSION marks the view as a dimension. @Semantics.text: true marks CustomerName as the readable text for the key.
A cube
A cube holds the facts, the numbers you analyze, plus links to the dimensions.
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales item cube'
@Analytics.dataCategory: #CUBE
define view entity ZI_SalesItemCube
as select from zsales_item
association [0..1] to ZI_CustomerDim as _Customer
on $projection.CustomerId = _Customer.CustomerId
{
key item_uuid as ItemUuid,
@ObjectModel.foreignKey.association: '_Customer'
customer_id as CustomerId,
@Semantics.currencyCode: true
currency as Currency,
@DefaultAggregation: #SUM
@Semantics.amount.currencyCode: 'Currency'
net_amount as NetAmount,
_Customer
}Three annotations carry the analytical meaning here:
@ObjectModel.foreignKey.associationtells the engine thatCustomerIdjoins to the dimension through_Customer.@DefaultAggregation: #SUMmakesNetAmounta measure that is summed when rows are grouped.@Semantics.amount.currencyCodeties the amount to its currency field, so amounts in different currencies are not added together blindly.
A query
A query view picks fields from a cube and places them on axes, like a pivot table.
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Net amount by customer'
@Analytics.query: true
define view entity ZC_NetAmountByCustomer
as select from ZI_SalesItemCube
{
@AnalyticsDetails.query.axis: #ROWS
CustomerId,
@AnalyticsDetails.query.axis: #COLUMNS
NetAmount
}This query puts customers on the rows and the summed net amount on the columns. The engine generates the grouping at runtime. You do not write a GROUP BY.
How the engine runs a query
Understanding the runtime path helps you diagnose problems later. When a front end requests a query, the sequence is roughly this:
- The front end sends an OData request that names the query and the fields, filters and sort order wanted.
- The analytical engine reads the metadata of the query view and its cube, including the annotations.
- The engine builds one SQL statement for HANA. It adds the joins for the associations that the request actually uses, and the GROUP BY for the fields requested.
- Access control conditions are added to the statement for the current user.
- HANA runs the statement and returns aggregated rows.
- The engine handles currency and unit semantics, then returns the result to the front end.
Two consequences follow from step 3:
- Only the associations used in the request are joined. A cube can expose many dimensions without paying for all of them on every run.
- Aggregation happens in the database. The application server receives the grouped result, not millions of line items.
Common errors and misconceptions
These are the problems learners most often hit when starting with embedded analytics.
- Treating it as a replacement for a warehouse. It reads current transactional tables. If the source archives or overwrites data, the analysis cannot see the old state.
- Reporting directly on tables. Querying tables bypasses the VDM, the annotations and the access controls. Build on views that carry meaning.
- Forgetting the authorization setting. A view with
@AccessControl.authorizationCheck: #NOT_REQUIREDapplies no row restrictions. That is acceptable for a harmless dimension such as a country list. It is a data leak risk on a cube that holds sales values. - Missing the currency link. A measure without
@Semantics.amount.currencyCodeis just a number. The engine cannot protect you from summing euros and dollars. - Assuming a query view works without a cube. A query needs a cube or another analytical source with the right data category. A plain view with no annotations is not enough.
- Expecting live to mean free. Every refresh runs against the operational database. Many users opening heavy queries at month end can compete with posting transactions.
Where the rest of the tutorial goes
The chapters that follow build the running example step by step:
- CDS view entities and associations, the base of everything.
- The VDM layers: interface, composite and consumption.
- Analytical annotations, then cubes and dimensions, then measures with currency and unit semantics.
- Query views, then access control with DCL.
- Key user tools for custom queries and KPIs, Fiori analytical apps, and consumption from other front ends.
- Performance and extensibility practices.
Exercises
Exercise
A colleague says, "Embedded analytics copies S/4HANA data into a separate analytical store each night." Is this correct? Explain how embedded analytics gets its data.
Show answer
No. Embedded analytics does not copy data. CDS views with analytical annotations read the live transactional tables in the same SAP S/4HANA system, and SAP HANA aggregates the data at query time. A nightly copy into a separate store describes a data warehouse approach.
Exercise
Your company needs one report that combines S/4HANA sales data with data from a non-SAP CRM system and keeps three years of history that S/4HANA archives after one year. Should you use embedded analytics alone? Give two reasons.
Show answer
No, a data warehouse is the better fit, possibly alongside embedded analytics. First, embedded analytics reads only the S/4HANA system, so it cannot combine the non-SAP CRM data. Second, it sees only what the transactional tables still hold, so history that S/4HANA archives is not available for analysis.
Exercise
In the cube example, what would go wrong if you removed @Semantics.amount.currencyCode: 'Currency' from NetAmount, and why does that matter for a query that sums by customer?
Show answer
The engine would no longer know that NetAmount is an amount tied to the Currency field. A customer with items in euros and dollars could end up with the two values added into a single meaningless number. The currency link lets the engine keep currencies apart or flag the mix.