Added
A sales analytics team needs a CDS entity that exposes a calculated gross margin percentage for each sales item. The percentage must be calculated by the database, avoid division by zero, and remain usable in consumers that aggregate by product. The source amount and cost are packed decimal fields, and the team must not change their database definitions. Which implementation is the best fit?
A CDS calculated element with CASE can handle a zero cost or denominator condition in the database, while an explicit cast controls the result type and precision. Because it is part of the CDS result, consumers can use it without fetching rows for ABAP-side calculation. A virtual element is calculated in ABAP and cannot provide the required database pushdown. An aggregation annotation does not itself define this row-level calculation. A table function adds unnecessary AMDP implementation and does not make the source decimal types safer than a well-typed CDS expression.