CDS View with Parameters

In CDS (Core Data Services) views, you can use parameters to create dynamic views that accept input values at runtime. These parameters can be used to filter or customize the data being retrieved, making the view more flexible and adaptable for different use cases.

Example of a CDS View with a Parameter

Create new CDS by write clicking on Package ➔ New ➔ Other ABAP Repository and Search Data Definition and select Data Definition as shown below and click next. Give name and description for your CDS. It will ask you for TR and click next.
Under View (creation), select DefineView template.
Below is the code to demonstrate how we can make CDS View with Parameter
The with parameters take input from user when CDS is executed. Below is the explanation of code.

Explanation:
Parameter Declaration: The with parameters clause defines a parameter, p_agency, of type /dmo/agency_id , which is utilized to filter the data.
Using the Parameter: The parameter p_agency is referenced as $parameters.p_agency in the where clause of the SQL query, allowing the data to be filtered based on the provided agency ID.
Key Points:
➯ Parameters enable you to filter or tailor the data returned by the CDS view dynamically at runtime.
➯ They allow external applications or reports to pass values into the view, enhancing its flexibility.
➯ You can define multiple parameters within the with parameters clause.

Let’s Run our CDS and give Agency ID as input
Click on F8, it will ask you for user parameter.
You have successfully learned CDS with Parameter. Don’t forget to checkout next tutorial to get more information on CDS View. Happy Learning!!!

Leave a Comment

Your email address will not be published. Required fields are marked *