SAP CDS WHERE CLAUSE V2



Get Example source ABAP code based on a different SAP table
  


• WHERE ABAP_CDS_SELECT

ABAP_CDS_DDL - CDS View Entity, SELECT, WHERE

ABAP_SYNTAX
... WHERE cds_cond ...

What does it do?
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.
lhs expects a field of a data source data_source, a path expression, a built-in function, an SQL-based scalar function, or a cast expression. 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.
rhs can be a field of a data source data_source, a path expression, a literal, a parameter, a session variable, a cast expression, a built-in function, or a SQL-based scalar function. If a comparison operator is used as relational operator, then rhs can also be a case expression or an arithmetic expression.
ABAP_EXCEPTION 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:
The cardinality of the contained CDS associations is to-one.
The path expression contains the cardinality specification attribute 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 parentheses . 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 parentheses does not appear as first operand. Example: ... WHERE 5 * (field1 + field2) < 1000
You may add 1* at the start to avoid starting with a parenthesis. Example: ... WHERE 1 * (field1 + field2) * 5 < 1000



Latest notes:

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

ABAP_EXAMPLE_VX5
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.
DDLS DEMO_SALES_ORDER_WHERE
ABAP_EXAMPLE_END