Ansicht
Dokumentation

ABENCDS_COALESCE_EXPRESSION_V2 - CDS COALESCE EXPRESSION V2

ABENCDS_COALESCE_EXPRESSION_V2 - CDS COALESCE EXPRESSION V2

ABAP Short Reference   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.
SAP E-Book

- CDS View Entity, Coalesce Function

... COALESCE( arg1, arg2 ) ...

Effect

Coalesce function in a SELECT statement of a CDS view entity. Can be used to check whether arg1 contains a null value. In ABAP CDS, the coalesce function has two mandatory positional parameters, arg1 and arg2. It checks whether arg1 contains a null value. If yes, then it returns the value of arg2. If no, then it returns the value of arg1. If both arg1 and arg2 are null, then the null value is returned.

The valid argument types for arg1 and arg2 are all dictionary types except ACCP, DF16_SCL (obsolete), DF34_SCL (obsolete), DF16_DEC, DF34_DEC, DF16_RAW, DF34_RAW, LCHR, LRAW, PREC, RAWSTRING, STRING, and GEOM_EWKB.

The data types of both arguments must either be the same or the data type of one argument must represent the value of the other data type. The result has the dictionary type of the argument with the largest value range.

Rules for Amounts and Quantities

The arguments of a coalesce function can be CDS amount fields, CDS quantity fields, or CDS calculated quantities. The following table shows how the result data type is calculated if one or more of the arguments are amount and/or quantity fields.

arg1/arg2 Amount Quantity Calculated Quantity Number
Amount Amount Calculated Quantity Calculated Quantity Calculated Quantity
Quantity Calculated Quantity Quantity Calculated Quantity Calculated Quantity
Calculated Quantity Calculated quantity Calculated quantity Calculated Quantity Calculated Quantity
Number Calculated Quantity Calculated quantity Calculated Quantity Number

  • If the result is an amount or quantity field, a reference annotation must be assigned.
  • It is not mandatory that the arguments 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.

Note

The coalesce function is a short form of the following complex case distinction:

CASE WHEN arg1 IS NOT NULL THEN arg1
     ELSE arg2
END

Example

The following CDS view entity demonstrates the syntax of the coalesce function.






rdisp/max_wprun_time - Maximum work process run time   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.

Length: 5705 Date: 20240424 Time: 045719     sap01-206 ( 86 ms )