CDS Annotations Part 2: Semantic Annotations for Currency, Units and Texts
Preview · a free account unlocks the full lesson
Make data self-describing with semantic annotations: amounts with currencies, quantities with units, text elements and text associations, languages, and admin fields that RAP maintains automatically.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 1 introduced the families of CDS annotations. Semantic annotations come first in this series because they describe what the data actually means, and every consumer of the data benefits from them.
Amounts and currencies are tied together with @Semantics.amount.currencyCode: 'CurrencyCode', applied above fields like net_amount as NetAmount and currency_code as CurrencyCode. This makes Fiori format the amount with the right number of decimals — none for JPY, two or three for most others — show the currency alongside it, and let analytics aggregate correctly per currency; the currency element itself has to be in the same view. The currency-code field doesn't need a separate annotation of its own — being referenced from the amount annotation is enough.
Quantities and units work the same way, with @Semantics.quantity.unitOfMeasure: 'OrderUnit' above fields like order_qty as OrderQuantity and order_unit as OrderUnit, giving correct display, conversion and aggregation per unit.
Texts for codes matter because users want to see "Completed," not "C." There are two ways to provide this. A text element in the same view uses @ObjectModel.text.element: ['StatusText'] on the code field, with StatusText calculated or read directly in the view.
A text association uses @ObjectModel.text.association: '_StatusText' on the code field, pointing to a text view annotated with @ObjectModel.dataCategory: #TEXT, where the language field carries @Semantics.language: true and the description field carries @Semantics.text: true.
Fiori then shows either "Completed (C)" or just the text, depending on @UI.textArrangement — and a text association automatically picks up the logon language, with no hard-coded language filter needed on the consumer side.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
Interview questions on this topic
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.