Sub topic 3
The Virtual Data Model: interface, composite and consumption views
This chapter assumes you can read basic SQL (SELECT, JOIN, GROUP BY) and know the S/4HANA business objects behind sales and customers. It also assumes you have seen the CDS view entity and association syntax from the previous chapter. You do not need to know the analytical annotations yet. This chapter shows the layering. Later chapters cover the annotation details.
Why a layered model exists
An S/4HANA system has thousands of CDS views. Without a rule for how they relate, every report would read database tables directly and repeat the same joins, currency handling and text lookups. A fix in one place would never reach the others.
The Virtual Data Model (VDM) is SAP's rule for this. It is a naming and layering convention for CDS views, and it is more than a technical feature. Each view belongs to one layer. Each layer reads only from the layer below it. Business meaning is added step by step.
For analytics, three layers matter:
- Interface views are the reusable foundation. They sit directly on database tables.
- Composite views combine interface views into larger business objects. Cubes are usually composite views.
- Consumption views are shaped for one use case, such as one query or one app.
The three layers in detail
Interface views
An interface view exposes a business entity close to its stored form. It renames technical fields to readable names, adds semantic annotations such as currency or text, and defines associations to related entities. It does not apply business filters or aggregations.
SAP calls the lowest sublayer basic views. They read one table (or a small tightly related set) and contain no complex logic. Other views then reuse them, so a field is renamed and annotated once.
Interface views should be stable. Other developers build on them, so changing a field name or meaning in one breaks everything above it. SAP ships interface views with the prefix I_. Customer-created views use the customer namespace, commonly ZI_.
Composite views
A composite view builds on interface views. It joins or associates several of them to describe a richer object, for example a sales item together with its customer, product and organization. It can add calculated fields, such as net amount minus discount, and it can aggregate.
In analytics, composite views are where cubes and dimensions are assembled. They stay reusable. Several queries can read the same cube, and each query decides what to show.
Consumption views
A consumption view serves one specific purpose. An analytical query view is the main example. It selects fields from a cube, places them on rows and columns, and sets filters and default behavior. SAP uses the prefix C_, and customers commonly use ZC_.
A consumption view must not be a source for other CDS views. It is the top of the stack. If you want to reuse its logic, move that logic down into a composite view.
Summary table
| Layer | Typical prefix | Reads from | Purpose | May contain |
|---|---|---|---|---|
| Interface (basic) | `I_` / `ZI_` | Database tables | Reusable, stable business entities | Renaming, semantics, associations |
| Composite | `I_` / `ZI_` | Interface and other composite views | Richer objects, cubes, dimensions | Joins, calculated fields, aggregation |
| Consumption | `C_` / `ZC_` | Composite views | One query or app | Axis layout, filters, UI-related annotations |
The prefix alone does not tell you the layer. SAP uses I_ for both interface and composite views. The annotation @VDM.viewType records the layer explicitly, so rely on it and not on the name.
Declaring the layer with @VDM.viewType
The @VDM.viewType annotation takes these values:
#BASICfor basic interface views.#COMPOSITEfor composite views.#CONSUMPTIONfor consumption views.#TRANSACTIONALfor views used by transactional apps.#EXTENSIONfor extension views that add fields to existing views.
The annotation does not change runtime behavior. It documents intent, and tools and checks use it to find the layer. Set it correctly so that naming rules, code reviews and the system's tooling agree.
Worked example: one stack, three layers
The next three views build one analytics stack on the hypothetical table zsales_item. The first is the basic interface view.
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Sales item (basic)'
@VDM.viewType: #BASIC
define view entity ZI_SalesItem
as select from zsales_item
{
key item_uuid as ItemUuid,
customer_id as CustomerId,
@Semantics.currencyCode: true
currency as Currency,
@Semantics.amount.currencyCode: 'Currency'
net_amount as NetAmount,
posting_date as PostingDate
}This view renames fields and marks the currency link. It has no join and no aggregation, so any other view can reuse it.
The second view is the composite cube. It reads the basic view, not the table, and it links to the customer dimension from the earlier chapter.
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales item cube'
@Analytics.dataCategory: #CUBE
@VDM.viewType: #COMPOSITE
define view entity ZI_SalesItemCube
as select from ZI_SalesItem
association [0..1] to ZI_CustomerDim as _Customer
on $projection.CustomerId = _Customer.CustomerId
{
key ItemUuid,
@ObjectModel.foreignKey.association: '_Customer'
CustomerId,
@Semantics.currencyCode: true
Currency,
@DefaultAggregation: #SUM
@Semantics.amount.currencyCode: 'Currency'
NetAmount,
PostingDate,
_Customer
}The third view is the consumption query. It reads the cube and decides the layout.
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Net amount by customer'
@VDM.viewType: #CONSUMPTION
@Analytics.query: true
define view entity ZC_NetAmountByCustomer
as select from ZI_SalesItemCube
{
@AnalyticsDetails.query.axis: #ROWS
CustomerId,
@AnalyticsDetails.query.axis: #COLUMNS
NetAmount
}Notice what each layer owns:
ZI_SalesItemowns the mapping from table columns to business names.ZI_SalesItemCubeowns the analytical meaning: it is a cube, the amount sums, and the customer is a dimension.ZC_NetAmountByCustomerowns the presentation: customers on rows, amount on columns.
If a second report needs net amount by month, you add a second consumption view on the same cube. The first two layers stay unchanged.
What changes where
The layering pays off when requirements change. The table shows where each kind of change belongs.
| Change request | Layer to change |
|---|---|
| A table column is renamed or moved | Interface view only |
| A new customer attribute is needed in reports | Dimension view (composite or interface) |
| A new calculated measure is needed by many reports | Composite view (the cube) |
| A report should show another column or a different sort | Consumption view only |
| A report must be limited to one company code | Access control, or the consumption view filter |
In each case the change is made once and flows upward. Upper layers are insulated from lower-layer changes as long as the field names exposed by the lower view stay the same.
Common errors
Reading tables from a consumption view. A query that selects from zsales_item directly skips the cube. It cannot reuse dimension associations or measure semantics, and it duplicates logic. Always read from the layer immediately below.
Skipping the interface layer. Building a cube straight on a table works technically. You then lose the reusable renamed entity, and each new cube repeats the column mapping.
Putting business logic in the consumption layer. If a calculation lives in a ZC_ view, no other report can use it. Move shared calculations into the composite view.
Using a consumption view as a source. Selecting from a C_ view in another CDS view couples your new view to a layout that can change for UI reasons. Select from the composite view instead.
Heavy logic in the basic layer. Joins, filters and aggregation in a basic view make it unsuitable for reuse. A basic view that already filters to one sales organization, for example, silently hides data from other users of the view.
Trusting the prefix. As noted above, I_ and ZI_ cover both interface and composite views. Check @VDM.viewType when you need to know the layer.
Changing a released view. Views that SAP delivers have a stability contract. Do not copy and edit them for your needs. Create your own views in the customer namespace on top of them, or use extension views as the extensibility chapter describes later.
Where authorizations and annotations fit
Annotations accumulate as you move up. Semantic annotations (text, currency, unit) are set low, so every consumer inherits them. Analytical annotations (@Analytics.dataCategory) are set in the composite layer. Query annotations (@Analytics.query, axis assignments) are set in the consumption layer.
Authorization checks follow the same idea. The @AccessControl.authorizationCheck annotation appears on every view in the example. In the example, the basic view uses #NOT_REQUIRED and the cube and query use #CHECK. The access control chapter explains how to write the rules and where to attach them so every consumer is covered.
Exercise
A colleague builds the view ZCSalesByMonth in the consumption layer. It contains a calculated field for net amount after discount, and a second report team now wants the same calculation. Where should the calculation live, and why shouldn't the second team select from ZCSalesByMonth?
Show answer
Move the calculation into the composite view (the cube, ZISalesItemCube). Both reports then read it from there. The second team should not select from ZCSalesByMonth because consumption views are the top of the stack and are shaped for one use. Its layout or filters can change for UI reasons, and that would silently change the second report.
Exercise
You find a view named I_ProductSalesOverview and you need to know whether it is an interface (basic) view or a composite view. Why can't you tell from the name, and what do you check instead?
Show answer
SAP uses the I_ prefix for both basic and composite views, so the name does not identify the layer. Check the @VDM.viewType annotation, which is #BASIC for a basic view and #COMPOSITE for a composite view.
Exercise
The table column netamount is renamed to netvalue in zsalesitem. In the example stack, which views must you edit for the report ZCNetAmountByCustomer to keep working?
Show answer
Only ZISalesItem, the basic view. Change its select list to read netvalue as NetAmount. The cube and the query read the field name NetAmount from the layer below, and that name has not changed.