ERPClimb logoERPClimb
CDS Annotations
RAP / CDS / ODataintermediate 9 min read

CDS Annotations Part 2: Semantic Annotations for Currency, Units and Texts

Preview · a free account unlocks the full lesson

Key takeaway

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 sections

Visual overview

CDS Annotations Part 2: Semantic Annotations for Currency, Units and Texts — learning sheetFlow: Annotate amounts and quantities in ZI_SalesOrderItem → Create the text view ZI_OrderStatusText (code example) and a text association in ZI_SalesOrder → Annotate admin fields in ZR_PurchReq → Preview in Fiori: amounts formatted, status shown as text. Key ideas: AMOUNTS AND CURRENCIES; QUANTITIES AND UNITS; TEXTS FOR CODES; ADMIN FIELDS FOR RAP. Watch out: Without semantics, Fiori shows raw numbers and analytics may sum different currencies.ERPClimb.com / RAP / LESSON 2/5 / LEARNING SHEETCDS Annotations Part 2: Semantic Annotations for Currency,Units and Texts1 · HOW IT FLOWS1Annotate amountsand quantitiesin…2Create the textviewZI_OrderStatusText…3Annotate adminfields inZR_PurchReq4Preview inFioriamounts formatted,status shown as text2 · KEY IDEAS EXPLAINEDAmounts And Currencies@Semantics.amount.currencyCode: 'CurrencyCode'Quantities And Units@Semantics.quantity.unitOfMeasure: 'OrderUnit'Texts For CodesText element in the same view:@ObjectModel.text.element: ['StatusText'] on thecode field, with StatusText calculated or read in…Text association: @ObjectModel.text.association:'_StatusText' on the code, pointing to a text viewannotated with @ObjectModel.dataCategory: #TEXT…Admin Fields For RAP@Semantics.user.createdBy: true,@Semantics.systemDateTime.createdAt: true,@Semantics.user.localInstanceLastChangedBy: true…3 · REMEMBER · WATCH OUTRememberEvery amount needs @Semantics.amount.currencyCode; every quantityneeds @Semantics.quantity.unitOfMeasure.Show texts next to codes with @ObjectModel.text.element or a textassociation.Admin fields (@Semantics.user.* / @Semantics.systemDateTime.*) arefilled automatically in managed RAP.!Watch outWithout semantics, Fiori shows rawnumbers and analytics may sumdifferent currencies.4 · IN A REAL PROJECTAn order-value dashboard summed NetAmount across all orders and showed one total. Orders were in EUR, USD andJPY, so the total was meaningless — and nobody noticed for weeks because the number looked plausible. Adding@Semantics.amount.currencyCode to the interface view made the analytics layer aggregate per currency…Original ERPClimb learning sheet • Verify against your SAP release and edition

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.

Free account

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

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.