Skip to content

Commit

Permalink
Add example for selecting from view with parameters (#839)
Browse files Browse the repository at this point in the history
Co-authored-by: Rene Jeglinsky <[email protected]>
  • Loading branch information
stewsk and renejeglinsky authored Nov 15, 2024
1 parent aab041d commit 32147e1
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions cds/cdl.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,37 @@ By using a cast, annotations and other properties are inherited from the provide

### Views with Parameters

You can equip views with parameters that are passed in whenever that view is queried. Default values can be specified. Refer to these parameters in the view's query using the prefix `:`.
You can equip views with parameters that are passed in whenever that view is queried. Default values can be specified.
Refer to these parameters in the view's query using the prefix `:`.

```cds
entity SomeView ( foo: Integer, bar: Boolean )
as SELECT * from Employees where ID=:foo;
```

When selecting from a view with parameters, the parameters are passed by name.
In the following example, `UsingView` also has a parameter `bar` that is passed down to `SomeView`.

```cds
entity UsingView ( bar: Boolean )
as SELECT * from SomeView(foo: 17, bar: :bar);
```

For Node.js, there's no programmatic API yet. You need to provide a [CQN snippet](/cds/cqn#select).

In CAP Java, run a select statement against the view with named [parameter values](/java/working-with-cql/query-execution#querying-views):

::: code-group
```js [Node]
SELECT.from({ id: 'UsingView'. args: { bar: { val: true }}})
```
```Java [Java]
var params = Map.of("bar", true);
Result result = service.run(Select.from("UsingView"), params);
```
:::


[Learn more about how to expose views with parameters in **Services - Exposed Entities**.](#exposed-entities){ .learn-more}
[Learn more about views with parameters for existing HANA artifacts in **Native SAP HANA Artifacts**.](../advanced/hana){ .learn-more}

Expand Down Expand Up @@ -1817,7 +1842,7 @@ service MyOrders {
entity OrderWithParameter( foo: Integer ) as select from data.Orders where id=:foo;
}
```
A [`view with parameter`](#views-with-parameters) modeled in the previous example, can be exposed as follows:
A parametrized view like modeled in the section on [`view with parameter`](#views-with-parameters) can be exposed as follows:

```cds
service SomeService {
Expand Down

0 comments on commit 32147e1

Please sign in to comment.