Looking at your specific requirement, here’s the proper solution addressing all three aspects of your CDS extension challenge.
CDS View Extension Syntax:
Your current extension is syntactically correct for adding fields, but you need to include the foreign key field that enables association resolution:
@AbapCatalog.sqlViewAppendName: 'ZVSORDEREXT'
extend view I_SalesOrderItem with Z_SalesOrderExt {
vbap.zzpriority,
vbap.zzcust_segment,
vbap.kunnr as CustomerNumber
}
Custom Field Mapping:
The key is exposing the join key (KUNNR) in your extension so downstream consumers can resolve associations. Don’t try to define associations within the extension itself - CDS extensions in 1809 don’t support association definitions.
Association Resolution:
Create a consumption view that layers on top of your extension:
define view Z_SalesOrderAnalytics
as select from Z_SalesOrderExt
association [0..1] to I_Customer as _Cust
on $projection.CustomerNumber = _Cust.Customer
{
key SalesOrder,
key SalesOrderItem,
zzpriority,
zzcust_segment,
CustomerNumber,
_Cust
}
This three-layer approach (base view → extension → consumption view) is SAP’s recommended pattern for analytics scenarios. The extension handles custom fields, the consumption view handles associations and filtering logic. Your analytics app then consumes Z_SalesOrderAnalytics where you have full association access.
Additional Tip: If you’re using this in embedded analytics or Fiori apps, add appropriate @Analytics annotations to the consumption view for proper aggregation behavior. This pattern also makes your solution more maintainable when you upgrade beyond 1809, as the separation of concerns is clear.
The syntax error you encountered is by design - it’s SAP’s way of enforcing clean extension patterns. Once you separate field extension from association logic, everything should work smoothly.