Skip to content

Commit 32147e1

Browse files
Add example for selecting from view with parameters (#839)
Co-authored-by: Rene Jeglinsky <[email protected]>
1 parent aab041d commit 32147e1

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

cds/cdl.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,12 +787,37 @@ By using a cast, annotations and other properties are inherited from the provide
787787

788788
### Views with Parameters
789789

790-
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 `:`.
790+
You can equip views with parameters that are passed in whenever that view is queried. Default values can be specified.
791+
Refer to these parameters in the view's query using the prefix `:`.
791792

792793
```cds
793794
entity SomeView ( foo: Integer, bar: Boolean )
794795
as SELECT * from Employees where ID=:foo;
795796
```
797+
798+
When selecting from a view with parameters, the parameters are passed by name.
799+
In the following example, `UsingView` also has a parameter `bar` that is passed down to `SomeView`.
800+
801+
```cds
802+
entity UsingView ( bar: Boolean )
803+
as SELECT * from SomeView(foo: 17, bar: :bar);
804+
```
805+
806+
For Node.js, there's no programmatic API yet. You need to provide a [CQN snippet](/cds/cqn#select).
807+
808+
In CAP Java, run a select statement against the view with named [parameter values](/java/working-with-cql/query-execution#querying-views):
809+
810+
::: code-group
811+
```js [Node]
812+
SELECT.from({ id: 'UsingView'. args: { bar: { val: true }}})
813+
```
814+
```Java [Java]
815+
var params = Map.of("bar", true);
816+
Result result = service.run(Select.from("UsingView"), params);
817+
```
818+
:::
819+
820+
796821
[Learn more about how to expose views with parameters in **Services - Exposed Entities**.](#exposed-entities){ .learn-more}
797822
[Learn more about views with parameters for existing HANA artifacts in **Native SAP HANA Artifacts**.](../advanced/hana){ .learn-more}
798823

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

18221847
```cds
18231848
service SomeService {

0 commit comments

Comments
 (0)