SAP CDS SEARCHED CASE EXPR V2 Get Example source ABAP code based on a different SAP table
SAP Help
• CASE WHEN ABAP_CDS_EXPRESSION
ABAP_CDS_DDL - CDS View Entity, searched_case_expr> ABAP_SYNTAX ... CASE WHEN cds_cond1> THEN result1 $[WHEN cds_cond2> THEN result2$] $[WHEN cds_cond3> THEN result3$] ... $[${ELSE resultn $| ELSE NULL$}$] END ...> What does it do? Complex case distinction> (searched case) in a SELECT> statement> of a CDS view entity>. The case distinction evaluates the conditions cds_cond1>>, cds_cond2>>, ... and returns the first operand specified after THEN> for which the comparison is true as result. If none of the conditions are true, the result is determined by the ELSE> branch: ELSE resultn> returns the value resultn>. ELSE NULL> returns the null value>. If ELSE > is not specified, the result is the null value >. The following rules apply to the conditions specified after WHEN>: All relational operators> are allowed. That means that comparison operators, BETWEEN>, LIKE >, IS NULL> and IS INITIAL> are allowed. The Boolean operators NOT>, AND>, and OR> are allowed. 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, then lhs> can also be an aggregate function>, a case expression>, an arithmetic expression, or a parameter. If the relational operator IS NULL> is used, then lhs> can also be another case expression>, an arithmetic expression>, or a parameter>. rhs> can be a field> of a data source data_source>>, a literal>, a parameter>, a session variable>, a cast expression>, a reuse expression>, a built-in function>, an SQL-based scalar function>, or a path expression. If a comparison operator is used, then rhs> can also be an aggregate function>, a case expression>, or an arithmetic expression>. ABAP_EXCEPTION for 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 targets> and the expression is unique: 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. Rules for Amounts and Quantities The result data type of a case expression is determined by all THEN > branches and the ELSE> branch. If the result data type is a CDS amount field>, a CDS quantity field>, or a CDS calculated quantity>, a reference annotation must be assigned. The following table shows how the result data type is calculated if one or more of the operands result1, result2,> ... are amount and/or quantity fields. operand1/operand2>Amount> Quantity> Calculated Quantity> Number> Amount>amount calculated quantitycalculated quantity calculated quantity Quantity>calculated quantityquantitycalculated quantity calculated quantity Calculated Quantity>calculated quantity calculated quantity calculated quantitycalculated quantity Number>calculated quantity calculated quantity calculated quantity number It is not mandatory that the operands and the result point to the same reference field. The following rules apply to amount fields of data type CURR>: fields of data type CURR> are compatible only to other amount fields of data type CURR> and only if they have exactly the same number of decimal places. To combine an amount field of data type CURR> with a field of another data type, a conversion to data type DECFLOAT34> using the conversion function CURR_TO_DECFLOAT_AMOUNT>> is required. Latest notes: