In this blog, we'll dive into multi-origin in CDS views, understand its use cases, and explore how to implement it with practical examples. By the end, you’ll have a clear understanding of why this feature is valuable and how to leverage it for your SAP S/4HANA applications.
Multi-origin in CDS views refers to the ability to handle data originating from multiple sources or tenants in a single data model. This is especially relevant for scenarios like:
The multi-origin feature uses a special field, typically referred to as the $session.client, or custom fields such as MANDT, to identify the data's origin.
Multi-Tenancy in S/4HANA:
Consolidated Reporting Across Clients:
Data Integration from Different Sources:
Multi-origin functionality is enabled using:
Below is a simple example of a CDS view for handling data from multiple clients
@AbapCatalog.sqlViewName: 'ZMULTIORIG'
@EndUserText.label: 'CDS View with Multi-Origin Support'
@AccessControl.authorizationCheck: #CHECK
define view ZMulti_Origin_Sales
as select from zsales_data
{
key SalesID as Sales_ID,
Client as Origin_Client, -- Represents the origin (MANDT)
CustomerID as Customer_ID,
SalesDate as Sales_Date,
ProductID as Product_ID,
Quantity as Quantity,
Amount as Amount
}
where Client = $session.client
Suppose you want to aggregate sales data across multiple origins (clients). Here's how you can extend the basic CDS view
@AbapCatalog.sqlViewName: 'ZMULTIORIGAGG'
@EndUserText.label: 'Aggregated Multi-Origin CDS View'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view ZMulti_Origin_Aggregated
as select from ZMulti_Origin_Sales
{
Origin_Client,
Product_ID,
sum(Amount) as Total_Sales
}
group by Origin_Client, Product_ID
For multi-tenant systems, you can use annotations like @Environment.systemField to simplify client filtering
@AbapCatalog.sqlViewName: 'ZMULTIORIGTEN'
@EndUserText.label: 'Multi-Tenant CDS View'
@AccessControl.authorizationCheck: #CHECK
define view ZMulti_Tenant_Sales
as select from zsales_data
{
key SalesID as Sales_ID,
CustomerID as Customer_ID,
SalesDate as Sales_Date,
ProductID as Product_ID,
Quantity as Quantity,
Amount as Amount
}
where Client = @Environment.systemField: client
Here, the annotation @Environment.systemField: client automatically handles the client filtering, reducing the need for explicit $session.client usage.
In some cases, you may want to disable client-based filtering to create a global view that includes all data from all origins
@AbapCatalog.sqlViewName: 'ZGLOBALVIEW'
@EndUserText.label: 'Global View Without Client Filtering'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@ClientHandling.type: #NONE
define view ZGlobal_Sales_View
as select from zsales_data
{
key Client as Origin_Client,
SalesID as Sales_ID,
CustomerID as Customer_ID,
SalesDate as Sales_Date,
ProductID as Product_ID,
Quantity as Quantity,
Amount as Amount
}
Here, the annotation @ClientHandling.type: #NONE disables client-specific filtering, making the view cross-client.
Here’s what the output might look like for the above views:
Sales_ID Origin_Client Customer_ID Sales_Date Product_ID Quantity Amount
1001 100 CUST01 2024-01-05 PROD001 10 500.00
1002 100 CUST02 2024-01-15 PROD002 5 250.00
Scenario 2: Aggregated Data Across Origins
Origin_Client Product_ID Total_Sales
100 PROD001 500.00
200 PROD002 1000.00
Scenario 3: Global Cross-Origin View
Origin_Client Sales_ID Customer_ID Sales_Date Product_ID Quantity Amount
100 1001 CUST01 2024-01-05 PROD001 10 500.00
200 1002 CUST02 2024-01-15 PROD002 5 250.00
Use Annotations:
Test for Performance:
Combine with AMDP or CDS Hierarchies:
Multi-origin in CDS views is a powerful feature that simplifies handling data from multiple sources or tenants. Whether you're building tenant-specific models, cross-client reports, or global views, understanding and leveraging this feature can enhance your SAP applications’ efficiency and scalability.