Let’s assume we have a data model, where we have shares, and each share has its own transaction history. For that we use an association [0..*] from the one share to the x transactions.
Now what we want to achieve is to display all these transactions inside the identification view.
To add this table, which usually is defined as a separate business object, we must make sure that our CDS entity view has correctly implemented the association.
@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions: true
@EndUserText.label: 'Data definition for portfolio'
define root view entity ZPORTFOLIO_I
as select from zportfolio
association [1..*] to ZPORTFOLIO_TRANS_I as _Transactions on $projection.Isin = _Transactions.Isin
{
@EndUserText.label: 'ISIN'
key isin as Isin,
name as Name,
code as Code,
exchange as Exchange,
// Association to the transactions
_Transactions,
@Semantics.user.createdBy: true
local_created_by as LocalCreatedBy,
@Semantics.systemDateTime.createdAt: true
local_created_at as LocalCreatedAt,
@Semantics.user.localInstanceLastChangedBy: true
local_last_changed_by as LocalLastChangedBy,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
local_last_changed_at as LocalLastChangedAt,
@Semantics.systemDateTime.lastChangedAt: true
last_changed_at as LastChangedAt
}
As we can see above the _Transactions association has been implemented and has been added as a field in the CDS definition.
Now in our metadata extension, we can use this association field as follows:
@Metadata.layer: #CUSTOMER
@UI.headerInfo.title: {
type: #AS_CONNECTED_FIELDS,
label: 'Share',
valueQualifier: 'HeaderTitle'
}
annotate view ZPORTFOLIO_I with
{
// ...
@UI.facet: [ {
id: 'partTransactions',
// Defines it as a table
type: #LINEITEM_REFERENCE,
// Defines, which association data it should display
targetElement: '_Transactions',
label: 'Transactions',
position: 20
} ]
_Transactions;
}
The association automatically fetches the corresponding entries which the currently selected share, since we have defined it in the CDS entity view.
Leave a Reply