Sub topic 2
Modeling a Cube and Its Dimensions
Assume you know basic SQL, SAP S/4HANA business objects, and the difference between transactional and analytical workloads. This chapter uses hypothetical tables named zcustomer and zsales_item.
Model the cube and dimensions
An analytical cube contains business events and measures, such as sales items and net amounts. A dimension describes the entities used to analyze those events, such as customers, products, or companies.
A dimension usually provides a stable key, a text field, and descriptive attributes:
@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 cube exposes the event data and associates its customer key with the customer dimension:
@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
}The foreign-key annotation tells analytical consumers how CustomerId relates to the dimension. The association also makes customer attributes available without duplicating them in the fact data.
Measures, currency, units, and aggregation
A measure is a numeric value that can be aggregated. #SUM defines the default aggregation for NetAmount. The currency annotation prevents consumers from treating amounts as currency-free numbers.
Use equivalent semantics for quantities and units. For example, a quantity should reference a unit field. Do not sum values with incompatible currencies or units unless the model supplies a conversion strategy.
Build an analytical query view
A query view defines the analytical layout consumed by reporting tools. This example places the customer on rows and the amount on columns:
@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 can now be consumed by an analytical application or another supported front end.
Exercise
Why should NetAmount reference Currency?
Show answer
The reference tells analytical consumers which currency applies to each amount, enabling correct display and currency-aware processing.