Extending SAP Gateway Service(CDS exposure) based standard report
This is another episode of how to extend standard SAP FIori application. In today’s episode, we will learn how to extend Fiori application that is based on Gateway Service which has data source reference to CDS view.
There are more than one type of SEGW project. The most common is SEGW project that implements ABAP code inside entity set class method to fetch the data. SEGW offers few other ways to fetch data without implementing ABAP code in the entity set class method. One example is to use data source reference to fetch data from CDS entity.
The setup
In this blog, we will add a custom field ‘Profit Center Source’ as a custom field to FIori app Display Group Journal Entries – With Reporting Logic(F3831). This app’s front end is based on UI5 but the backend is based on gateway service and it is using data source reference.
1. Identity backend Odata service and CDS view
The Fiori app is based on Odata and it is coming from SAP Gateway Service. You can identify such app if the app is based on Odata service and this service is created from tcode SEGW. If you check the odata, the data source is referencing CDS view and hence the data source of this app is coming from CDS view. https://fioriappslibrary.hana.ondemand.com/sap/fix/externalViewer/#/detail/Apps(‘F3831’)/S27OP
You can see that there is no entity types and sets defined on the SEGW project. Everything is referencing the CDS views by Data Source Reference.
2. Identity Entity Set and base CDS view
As you can see, there are many CDS entity set referred in this project. We must identify which one is being called from the Fiori app.
To identity which entity set is being called from the app, open the Fiori app and perform the data selection with browser development tool(F12). In the example app, press Go. Now you can see the Odata is being called.
Go to the payload tab and you can see that entityset called ‘CnsldtnGrpJrnlItem’ is called.
Now we have identified that ‘CnsldtnGrpJrnlItem’ is the entityset being called.
Let’s look at what CDS view is used for ‘CnsldtnGrpJrnlItem’. Double click ‘CDS-Entity Exposure’ and all the CDS views used. But if you look at ‘CnsldtnGrpJrnlItem’, this is not a CDS view and you won’t find it in the system.
There are two reasons for this.
Firstly ,it’s because the names are in external format. Click on Internal Names to display the internal name. Now they are all in CDS view names.
However there is still no’CnsldtnGrpJrnlItem’. This is because entityset ‘CnsldtnGrpJrnlItem’ is redirected to another entityset. Double click association and yot can see that ‘CnsldtnGrpJrnlItemParameters’ which is the entity type of ‘CnsldtnGrpJrnlItem’ is redirected to CnsldtnGrpJrnlItemResult.
‘CnsldtnGrpJrnlItemResult’ does exist in the Exposed CDS Entity as external name. As internal name, it’s ‘C_CNSLDTNLOGICBASEDGRPJEITM’.
You should find the CDS view in ADT .
3. Extend CDS view with custom field
Extend ‘C_CNSLDTNLOGICBASEDGRPJEITM’ and it’s base CDS ‘I_CnsldtnGrpJrnlItemC’. First, create an extension view for ‘I_CnsldtnGrpJrnlItemC’ as this is the base. Add Profit Center Source from existing association _ProfitCenter._MDSource.AdditionalMasterDataSource.
@AbapCatalog.sqlViewAppendName: 'YCNSGRPJEICE'
@EndUserText.label: 'Extension C_CNSLDTNLOGICBASEDGRPJEITM'
extend view I_CnsldtnGrpJrnlItemC with YCNSLDTNGRPJRNLITEMC_E
{
@EndUserText.label: 'Profit Center Source'
_ProfitCenter._MDSource.AdditionalMasterDataSource as ProfitCenterSource
}
Next, create an extension view for the top layer CDS ‘C_CNSLDTNLOGICBASEDGRPJEITM’ and add the Profit Center Source we added in the previous step.
@AbapCatalog.sqlViewAppendName: 'YCNSGRPJEIE'
@EndUserText.label: 'Extension C_CNSLDTNLOGICBASEDGRPJEITM'
extend view C_CnsldtnLogicBasedGrpJEItm with YCNSLDTNLOGICBASEDGRPJEITM_E
{
@EndUserText.label: 'Profit Center Source'
CnsldtnGrpJrnlItemC.ProfitCenterSource
}
In normal case…
this will is all it needs to add the custom fields.
However, Display Group Journal Entries – With Reporting Logic(F3831) is special because in I_CnsldtnGrpJrnlItemC which has redirect class defined. This means that when Fiori app that reads CDS C_CnsldtnLogicBasedGrpJEItm read data from this cube, it will instead redirected to ABAP class CL_FINCS_GRA_CUBE_REL and whatever data is fetched there will be reutnred to CDS C_CnsldtnLogicBasedGrpJEItm and then to Fiori app. You will require a developer to find out the real data source CL_FINCS_GRA_CUBE_REL is using to fetch the data from. In this document, how to find that data source is skipped, and providing that I_MatrixCnsldtnFndnPeriodic is the CDS view CL_FINCS_GRA_CUBE_REL is fetching data from in the ABAP class.
So in conclusion, we implemented extension view in I_MatrixCnsldtnFndnPeriodic and add Profit Center Source as well.
So as the last step, create an extension view for I_MatrixCnsldtnFndnPeriodic and add the Profit Center Source we added in the previous step.
@AbapCatalog.sqlViewAppendName: 'YMTRXCSLDPERE'
@EndUserText.label: 'Extension I_MatrixCnsldtnFndnPeriodic'
extend view I_MatrixCnsldtnFndnPeriodic with YIMatrixCnsldtnFndnPer_E
{
@EndUserText.label: 'Profit Center Source'
_ProfitCenter._MDSource.AdditionalMasterDataSource as ProfitCenterSource
}
Go to Fiori app and run the report. Go to setting and Profit Center Source should be there so add it as column. The report should now display custom field Profit Cneter Source with data.