Sub topic 3
The Virtual Data Model: interface, composite and consumption views
This chapter assumes you can read basic SQL, know what a CDS view entity is (a named, annotated SELECT definition), and know how an association links two views. You should also know the difference between transactional (OLTP) and analytical (OLAP) workloads.
Why the Virtual Data Model exists
An S/4HANA system holds thousands of database tables with short, technical names. Building reports directly on them would be slow to write and fragile to maintain. The Virtual Data Model (VDM) is SAP's layered set of CDS views that sits on top of those tables. It gives business meaning to the data and stacks views so that each layer has one job.
The VDM does not copy data. Every view is evaluated at query time against the live tables, which is why embedded analytics can report on current transactional data.
The three layers
Views in the VDM fall into three layers. Each layer reads from the one below it.
| Layer | Purpose | Typical content | Who uses it |
|---|---|---|---|
| Interface (basic) | Stable, reusable business entities built directly on tables | Cubes, dimensions, and views with readable field names | Other views, not end users |
| Composite | Combines interface views for a specific scenario | Joins, calculated fields, additional associations | Other views and queries |
| Consumption | Shaped for one use, such as a report or an API | Analytical queries, UI-specific views | Apps and front ends |
Many SAP delivered views use the prefixes I_ for interface, C_ for consumption and often R_ for restricted reuse. This tutorial uses the names ZI_ and ZC_ for custom interface and consumption views. Your project may use a different convention, so follow the one your team already has.
The arrow from interface views straight to consumption views is deliberate. A simple query can read an interface cube directly. You only add a composite layer when you need to combine or enrich data.
What belongs in each layer
Interface views
Interface views map tables to business concepts. They rename technical fields, define keys, declare associations, and carry the semantic annotations for amounts, currencies and texts. The cube ZI_SalesItemCube and the dimension ZI_CustomerDim from this tutorial are interface views.
Keep interface views free of scenario-specific logic. If many queries depend on a view, a change to it affects all of them.
Composite views
A composite view builds on interface views. Use one when several queries need the same combination, for example sales items enriched with product group and customer region. Putting that logic in one composite view avoids copying it into each query.
Consumption views
A consumption view is what a front end sees. For analytics, it is usually an analytical query. It chooses the fields, puts them on rows or columns, and sets filters or variables. It should contain no business logic that another query might need.
A worked example
Consider the views from the plan. The layering looks like this:
ZI_CustomerDimis an interface view over the tablezcustomer.ZI_SalesItemCubeis an interface view overzsales_itemand associates to the dimension.ZC_NetAmountByCustomeris a consumption view that reads the cube.
The consumption view is short because the lower layers already did the work:
@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
}The query selects from ZI_SalesItemCube, not from zsales_item. If the source table changes, you fix the cube once and the query keeps working.
Common errors
- Reading tables from a consumption view. This skips the semantics defined in the interface layer, so amounts lose their currency handling and fields lose their texts.
- Putting scenario logic in an interface view. Other consumers then inherit behavior they did not ask for.
- Duplicating a join across queries. Move it into a composite view.
- Depending on a view not released for your use. SAP can change unreleased views between releases. Prefer released views and your own interface views.
Exercise
Your team has three analytical queries that each repeat the same join of sales items to product groups. In which VDM layer should you place that join, and why?
Show answer
In a composite view built on the interface views. The join is shared by several queries, so defining it once avoids duplication and keeps changes in one place. The queries then read from the composite view as consumption views.