Technical Articles
Add Parameters in Custom CDS Views in S/4HANA Cloud
Hi Friends,
In this blog post I’m going to show how you can add parameters in custom CDS views built in S/4 HANA Cloud environment. Sometimes it is required and quite useful when you add parameters to your views so that when view is being called, those parameters will be passed to underlying data objects and only specific records will be retrieved.
Let’s consider a scenario where we need to get data from material stock based on posting date.
To achieve this, create a custom CDS view based on standard CDS view I_MaterialStock.
Navigate to “Parameters” tab and add an entry, let’s say it, ToDate. We can choose any default value to set, it can be a manual date or system default date as well.
Switch to “Filters” tab and edit it. Add a filter for Posting Date is less than equal to date from parameters, as shown below –
Now apply the changes and save the CDS view. When we preview the view, parameters pop up for ‘To Date’ will appear where date needs to be entered. After entering the date, data will be retrieved based on filter criteria.
Additionally, when you expose this CDS view as cube and build a Custom Analytical Query on top of this, these parameters will be pulled up as selection criteria in the query.
To conclude, we can add parameters to filter the records at database level itself which can be consumed in queries or applications
Thanks,
Saurabh
Interesting - you added the parameters to a standard SAP CDS. I didn't know you could do that. It might be an on-cloud vs. on-prem thing. I'm on premise.
For custom CDS I simply type in the parameters. I've also used filters.
Thank you for the blog - I'll have to see if I can do it on-prem.