This topic demonstrates how you can expand the syntax of the CDS view to include metadata with the aim of providing some additional list reporting capabilities.
@UI.headerInfo: { typeName: 'Sales Order Item', typeNamePlural: 'Sales Order Items' } define view ZDEMO_CDS_SalesOrderItem_A as ...
Preview:
@Search.searchable: true define view ZDEMO_CDS_SalesOrderItem_A as ... @Search.defaultSearchElement: true Item.Product as Product, ...
Preview:
@UI.selectionField.position: 10 key Item.SalesOrder as SalesOrderID, ... @UI.selectionField.position: 20 @Search: { defaultSearchElement: true, fuzzinessThreshold: 0.7 } Item._SalesOrder._Customer.CompanyName as CompanyName, ...
Preview:
It is not required for the ItemPosition field to appear as a separate field in the result Sales Order list. Therefore, this field should be hidden in the list and therefore not available for the personalization settings dialog.
... @UI.hidden: true key Item.SalesOrderItem as ItemPosition, ...
In the list, the Sales Order ID field should get a specific label (Sales Order) and be displayed at the first position within the result list.
... @UI.lineItem: { importance: #HIGH, label: 'Sales Order', position: 10 } key Item.SalesOrder as SalesOrderID, ...
The order of fields is continued with currency and both amount fields:
... @UI.lineItem.position: { position: 40, importance: #HIGH } Item.GrossAmountInTransacCurrency as GrossAmount, @UI.lineItem.position: 50 Item.NetAmountInTransactionCurrency as NetAmount, @UI.lineItem.position: 60 Item.TaxAmountInTransactionCurrency as TaxAmount ...
The customer’s Company name should also appear in the list:
... @UI.lineItem.position: 20 Item._SalesOrder._Customer.CompanyName as CompanyName, ...
The Product appears as third field in the list:
... @UI.lineItem.position: 30 Item.Product as Product, ...
Preview:
It is not required for the currency field to appear as a separate field in the result list. The currency code has only to be displayed in connection with the amount data instead. This is implemented by the annotation @Semantics.currencyCode: true. The annotation @Semantics.amount.currencyCode: 'CurrencyCode' defines each amount element as a currency field.
The @DefaultAggregation: #SUM annotation is used for analytical capabilities: The annotated amount fields are specified as so-called measures, that is, fields that can be aggregated.
... @Semantics.currencyCode: true Item.currency_code as CurrencyCode, ... @Semantics.amount.currencyCode: 'CurrencyCode' @DefaultAggregation: #SUM Item.GrossAmountInTransacCurrency as GrossAmount, ... @Semantics.amount.currencyCode: 'CurrencyCode' @DefaultAggregation: #SUM Item.NetAmountInTransactionCurrency as NetAmount ... @Semantics.amount.currencyCode: 'CurrencyCode' @DefaultAggregation: #SUM Item.TaxAmountInTransactionCurrency as TaxAmount, ...
Preview:
The aggregated fields display the sum - given that all amount elements are lineked to one and the same currency:
Apart from that, the aggregation does not work if the amount elements of a currency field are linked to various currencies:
In order for the amount elements of a currency field to be aggregated, an unitary currency is required. ABAP CDS provides the currency conversion function that we can use for that purpose. In our example, EURO is specified as the taget currency. The value 'EUR' is passed to the formal paramter taget_currency to be linked with the amount value of the conversion function. In the case of an error, for example when a currency does not exist, the result is set to null value.
... @Semantics.currencyCode: true cast( 'EUR' as abap.cuky ) as TargetCurrency, @UI.lineItem:{ label: 'Gross Amount in EUR', position: 45 } @DefaultAggregation: #SUM @Semantics.amount.currencyCode: 'TargetCurrency' CURRENCY_CONVERSION( amount => Item.GrossAmountInTransacCurrency, source_currency => Item.TransactionCurrency, target_currency => cast( 'EUR' as abap.cuky ), exchange_rate_date => cast( '20160101' as abap.dats ), error_handling => 'SET_TO_NULL' ) as ConvertedGrossAmount ...
Preview: