Technical Articles
SAP Fiori List Report Utilizing CDS View with Parameters
Hi Folks,
In this blog we’re going to develop an SAP Fiori Elements (List Report) Application utilizing CDS view with parameter.
I checked in lots of blogs statement that Standard List Report doesn’t not support CDS view with parameter.
I found a solution and we just need to use single property in our manifest.json file to achieve it.
Below are the steps we need to do:
- CDS View source code
- Metadata of CDS view
- Web IDE code
- CDS View source code
@AbapCatalog.sqlViewName: 'ZCQMBTHFLGUXPOC'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #CONSUMPTION
@OData.publish: true
@EndUserText.label: 'Batch Flagging Activities Report'
@UI.headerInfo: {
typeName : 'Batch Flagging Activities Report' ,
typeNamePlural: 'Batch Flagging Activities Report' }
define view ZC_QM_BTHFLG_POC_UX
with parameters
@EndUserText.label: 'History/Current'
@Consumption.defaultValue: 'Current'
@Consumption.valueHelpDefinition:[{entity:{name : 'ZI_Current_History',
element : 'Status'}}]
hist_curr : char7,
@EndUserText.label: 'Start Date'
@Environment.systemField: #SYSTEM_DATE
S_Date : dats,
@EndUserText.label: 'End Date'
@Environment.systemField: #SYSTEM_DATE
E_Date : dats,
@EndUserText.label: 'Plant'
@Consumption.valueHelpDefinition:[{entity:{name : 'I_Plant',
element : 'Plant'}}]
ip_Plant : werks_d
as select from ZI_QM_HIST_CURR_001 (S_Date:$parameters.S_Date,E_Date:$parameters.E_Date,
ip_Plant:$parameters.ip_Plant,
hist_curr:$parameters.hist_curr)
{
@EndUserText.label: 'Material'
@UI.selectionField.element: 'Material'
@UI.lineItem.position: 10
key Material,
_matnr_txt,
@EndUserText.label: 'Batch'
@Consumption.semanticObject: 'Batch'
@UI.lineItem.position: 20
key Batch,
@EndUserText.label: 'Change Control'
@UI.lineItem.position: 30
@UI.selectionField.element:'Change Control'
CC_ID,
@EndUserText.label: 'Flag/ Unflag'
@UI.lineItem.position: 40
@UI.selectionField.element:'Flag'
Flag,
@EndUserText.label: 'Flagging Type'
@UI.lineItem.position: 50
@UI.selectionField.element:'Flagging Type'
FlaggingSource,
}
2. Metadata of CDS view:
As I made 4 fields as parameterized, we can see in the below screenshot of Metadata of CDS view.
3. SAP Web IDE code:
- Select a List Report template Application-> Click on Next
- Enter the project details -> Click on Next
- Select the system -> Select the OData service -> Click on Next
- Select the Annotations files-> Click on Next
- Select the OData Collection -> Click on Finish
- Open the json file from the project structure.
- Add “considerAnalyticalParameters”: true as highlighted in below screenshot.
- Run the application
- Fill all the mandatory parameter-> click on Go
As you can see in the above screenshot the data is coming.
So, folks cheers we can use CDS view with Parameters in List Report Application. We don’t need any extension or any extra code for Parameterized CDS.
I hope this simple trick can help you guys to consume CDS view with Parameters in List Report Application template.
Regards,
Ankur Bajpai
Thanks for blog and I was looking for it.
I have question. As per my knowledge, CDS view parameters can take single value at a time. Since we are fiori List report application, End user can search for multiple values.
In your example, I want to search for plants 1234 , 5678. Does this work with CDS view parameters + Fiori App.
Best wishes,
Ramjee
Yeah, I agree ramjee korada As we can pass single value in CDS view with Parameters, same thing we can do here from Fiori Elements(List Report) application.
For multiple selection of the field I think we need to go with CDS view without parameter.
Thanks,
Ankur Bajpai
Coooool! 🙂
Thanks Ankur!
🙂 Thorsten Klingbeil
Thanks!
Thanks Aknur!
Very useful, I am currently trying to use analytical parameters but with Java and Apache Olingo in BTP. It would be interesting if SAP spent more time developing annotations for Apache Olingo + HANA Database + OpenUI5. I think that I can provide some scripts that we had to develop in our project to extend the EDM adding specific annotations for SAP (like ValueList, LineItems, etc.).
That would be really amazing!
Nice trick, very useful
Thanks François Henrotte:)
Hi Ankur,
Very nice blog! When I am trying to achieve same I am getting $batch exception . Exception is raised with message
"The caller violated a precondition for a method call" in Fiori .
When I separately run Odata by passing parameters I am getting result .
Thanks
Shweta
Hi Shweta Sahay ,
I hope your query also resolved by Axel Mohnen .
Thanks,
Ankur Bajpai
Hi Ankur,
Thanks a lot for the excellent blog.
I tried to follow your example, but in the smart filter bar I only see the "Parameters" fields like S_Date. The key field "Material" is not visible at all either in the smart filter bar nor in the "adapt filter" popup.
Do I miss something?
Thanks a lot.
Kind regards
Axel
Hi Ankur,
it works now. I selected just the wrong Entityset.
@Shweta: I had the same issue:
"The caller violated a precondition for a method call" in Fiori .
When I separately run Odata by passing parameters I am getting result .
I forgot the parameter “considerAnalyticalParameters”: true in the manifest.
Kind regards
Axel
Hi Axel Mohnen
Sorry I was not much active. Thanks for posting resolution!
Thanks,
Ankur Bajpai
Hi Ankur,
Thanks for this, very helpful !! I have a question. Can we also put parameterized CDS views as value helps using the annotation @Consumption.valueHelpDefinition.
For ex: in the above, you have used a parameter s_date. So suppose i want to pass this parameter further to a value help for one of the projection list fields, is that possible?
I tried with the "additional bindings" annotation but it didnt work.
Please let me know your thoughts on this.
Thanks,
Govind
Hi Govind Narayanan ,
Sorry for late reply, I guess it should work as you can see in my CDS view code I used for multiple parameters.
Please let me know if more inputs needed.
Thanks,
Ankur Bajpai
Hi Ankur,
Thanks for the response. What i meant is suppose in your example, we need a value help definition for the field 'Material'.
Now, i want to restrict the number of materials shown on the value help based on the start date parameter, that is, I want the value help of material shown on UI to be dynamic based on whatever value is inputted on the Start Date parameter.
Is that something possible through the @Consumption.valueHelpDefinition annotation or any other way?
Thanks,
Govind
Hi Ankur Bajpai
I would like to navigate from overview page to list report with some filters
Does above solution works for my criteria