Ansicht
Dokumentation

ABENCDS_WHERE_CLAUSE_V2 - CDS WHERE CLAUSE V2

ABENCDS_WHERE_CLAUSE_V2 - CDS WHERE CLAUSE V2

General Data in Customer Master   General Material Data  
This documentation is copyright by SAP AG.
SAP E-Book

- CDS View Entity, SELECT, WHERE

... WHERE cds_cond ...

Effect

Defines a WHERE condition for the result set of a CDS view entity. When the CDS view entity is accessed, the result set contains only the data from the data source data_source that meets the condition cds_cond specified after WHERE.

The fields evaluated in the condition do not need to be defined as elements of the CDS view entity in the SELECT list.

If the view entity makes use of multiple data sources by using join expressions, then all fields specified in the WHERE condition must be prefixed with the name of their data source separated by a period (.). The prefix is required in all cases, even if the field names are unique.

The following rules apply to the operands and syntax of the WHERE condition of a CDS view entity:

  • All relational operators are allowed. That means all comparison operators are allowed as well as BETWEEN, LIKE, IS [NOT] NULL, and IS [NOT] INITIAL.
  • The Boolean operators NOT, AND, and OR are supported.
If a comparison operator is used as relational operator, then lhs can also be a literal, a case expression, or an arithmetic expression.
If IS NULL is used as relational operator, then lhs can also be a case expression.
If a comparison operator is used as relational operator, then rhs can also be a case expression or an arithmetic expression.
  • when using the operator LIKE, rhs must be a character literal.

  • A field of a data source can be specified using a path expression path_expr.element, as long as the CDS associations of the expression do not have any non-SQL CDS entities as association target and the cardinality of all traversed associations is to-one:

element can be used to specify an element of the association target of the last CDS association of the path.
  • Other expressions and function calls are not allowed.

Limitation

The condition in the WHERE clause must not start with brackets. This is not valid:

... WHERE (field1 + field2) * 5 < 1000

The following workarounds are possible:

  • You may change the order of the operands so that the expression written in brackets doesn't appear as first operand.
Example: ... WHERE 5 * (field1 + field2) < 1000
  • You may add 1* in the beginning to avoid starting with a bracket.
Example: ... WHERE 1 * (field1 + field2) * 5 < 1000

Note

Unlike in the HAVING condition, aggregate expressions cannot be specified in the WHERE condition.

Example

The CDS view entity demo_sales_order_where has a WHERE condition that contains the relational operators LIKE and BETWEEN, a string function, and a cast expression.






General Data in Customer Master   BAL Application Log Documentation  
This documentation is copyright by SAP AG.

Length: 8878 Date: 20240426 Time: 053112     sap01-206 ( 84 ms )