Use Metadata Extension to extend SAP Fiori app based on CDS Query
Metadata extension is an independent ABAP development object which helps define UI semantics for CDS consumption view. It helps to separate the UI semantics annotation into separate object called metadata extension.
To allow metadata extension, the consumption view must have annotation ‘@Metadata.allowExtensions’. This annotation explicitly permits the use of metadata extensions.
Now this metadata extensions comes in handy when customer wants to extend standard Fiori app that is based on CDS consumption view, such as the case for CDS Query based Fiori app.
The Setup
In this blog, we are going to extend annotation of Profit Center field in Journal Entry Analyzer(F0956) app. This app comes with Profit Center as report dimension, but it is not set as filter so we are going to set it as a filter by using metadata extension.
Identify CDS view Query
Find out how to identify CDS view Query for Journal Entry Analyzer(F0956) by following my blog at Extending SAP Fiori app based on CDS Query .
Open the CDS query C_GLLineItemsQ0001 and you can see that ProfitCenter has no annotation to make it appear as filter.
Changing C_GLLineItemsQ0001 and adding the filter annotation directly will be modification of standard object so in this case annotation extension is used to avoid modification.
Before creating the extension, we must check that annotation is extendable for this Query. If there is annotation ‘@Metadata.allowExtensions: true’ in the view header, it is extendable, if not, this solution does not work.
Create Metadata Extension
Right click on the package and create Core Data Service with Metadata Extension. Enter C_GLLINEITEMSQ001 as extended entity.
In metadata extension you can add custom annotation to the existing field, such as ProfitCenter. Add filter annotation as below and Activate.
@Metadata.layer: #CUSTOMER
annotate view C_GLLineItemsQ0001 with
{
@Consumption.filter: { selectionType: #HIERARCHY_NODE, multipleSelections: true, mandatory: false }
ProfitCenter;
}
You should be able to see Profit Center as filter in the Fiori app.