SAP CDS REUSABLE EXPRESSION V2 Get Example source ABAP code based on a different SAP table
SAP Help
• $projection ABAP_CDS_EXPRESSION
ABAP_CDS_DDL - CDS View Entity, $projection> ABAP_SYNTAX ... $projection.reuse_exp ...> What does it do? $projection.reuse_exp> reuses expressions defined in the SELECT> list select_list>> of a CDS view entity> in an operand position of the SELECT> list of the same CDS view entity. Reuse expressions can currently be used in the following operand positions: In the SELECT> list as part of an expression. In the ON> clause of an CDS association> (as described in topic CDS DDL - CDS View Entity, ASSOCIATION>>. The reused expression reuse_exp> can contain the following operands or expressions: A field> of a data source data_source>> of the current CDS view entity a literal> An arithmetic expression> A cast expression> A built-in function> A SQL-based scalar function> A case distinction> ABAP_RESTRICTIONS Cycles must not occur and result in a syntax check error. The following represents a cycle and is not allowed. ... { a + $projection.z as x, 2 * $projection.x as y, b + $projection.y as z } ...> Explanation: element x uses z, which in turns uses y, which again uses x . Currently, reuse expressions cannot> be used in the WHERE>>, GROUP BY>>, or HAVING>> clause or within a filter condition>. Parameters>, session variables>, path expressions>, and aggregate functions> are currently not> possible as part of the reuse expression. If you try to reuse such an element of the SELECT > list, an error message occurs. If a field is specified as CDS amount field > or CDS quantity field> by assigning a currency key or unit key, and if this field is reused in the same view with $projection>, then the reference information is lost and the field is handled as normal numeric value. If a calculated quantity> is reused via $projection>, the reference information is lost, but the characteristic as calculated quantity is kept. The required reference information needs to be assigned to the result. ABAP_RESTR_END ABAP_EXAMPLE_VX5 Reuse of expressions in a SELECT> list. DDLS DEMO_CDS_EXPRESSION_REUSE ABAP_EXAMPLE_END