Input Parameter Declaration
The new possibilities immediately raise the question of how far the customer of the CDS view can influence the way calculation is done. Of course, the consumer can provide a WHERE clause to select the results. But how does that help when you want to specify the target currency for currency conversion?
CDS views that contain an aggregation expression are another important example of the need for input parameters. If, for example, a CDS view calculates the sum of revenues, the view itself can restrict the revenues that enter the equation. But fields like the booking date will not be part of the view’s element list and the consumer of the view will have no chance to refer to it in his WHERE clause.
Finally, SQL does not know such things as mandatory selection criteria. A consumer may provide a WHERE clause or might not. With a mandatory input parameter, the view can force the consumer to provide a necessary selection criterion like e.g. a language key or a user name.
You define input parameters by placing addition WITH PARAMETERS after the CDS View name. The parameters are then defined in a comma-separated list.
Each input parameter must be typed with an elementary data type. This can be a predefined ABAP Dictionary type or a data element. Structure types, table types or reference types are not allowed.
You can use annotations to provide additional information for parameters. Annotations LIKE annotations in the element list, annotations in the parameter list can be specified before the parameter or after the parameter.
Template defineViewWithParameters
There is a dedicated template for creating a view definition with input parameters.
Access to Input Parameters
There are two ways to address input parameters: the long version is with the prefix “$parameters.”, the short version is a simple colon (“:”) before the parameter name. It is recommended to use the long version. Only the long version is supported by source code completion.
Input Parameters in Data Preview
If you open Data Preview for a CDS View with input parameters, you are prompted to enter actual values for all input parameters.
Only such entries are accepted that are compatible with the parameter type. But the tools do not perform any further checks. If, for example, the parameter is typed with a data element that is based on a domain, the entry is not checked against the allowed fixed values in this domain.
Input Parameters in CDS DDL
When a CDS view reads from another CDS view that has input parameters, all these input parameters must be supplied with actual values. This is done with parenthesis immediately after the name of the source view in the FROM clause. No blanks are allowed before the opening parenthesis.
You can use the following as an actual value for an input parameter:
Input parameters in Open SQL
In Open SQL, actual parameters for the input parameters of a CDS view are specified in a parenthesized comma-separated list. The syntax is very similar to that used in CDS DDL. There are two important differences:
The following can be used as actual parameters: