SAP CDS Annotations: The Ones You Will Use on Every Project

Abhinav Khasale · 31 January 2025 · 3 min read

The CDS annotations S/4HANA developers use most: labels, authorization checks, currency and unit links, Fiori list and filter fields, analytics and metadata extensions.

Annotations are the lines starting with @ in a CDS definition. They leave the SELECT logic alone and add metadata that the ABAP runtime and SAP frameworks read: labels, currency references, authorization checks, Fiori columns and analytics behavior. Get them right and a Fiori elements app needs very little front-end code.

Syntax in one minute

• The form is @Domain.name: value . Values can be quoted text, true or false , numbers, enum values such as #CHECK , or arrays in square brackets.

• Annotations before define view entity apply to the whole view; those directly before a field apply to that field.

• In the ADT editor, put the cursor on an annotation and press F1 for its documentation and allowed values.

Two kinds: ABAP and framework-specific

ABAP annotations are evaluated by the ABAP runtime and the CDS activation, for example @AbapCatalog , @AccessControl and @EndUserText . Framework-specific annotations are evaluated at runtime by one framework: SADL and Fiori elements ( @UI ), Analytics ( @Analytics , @Aggregation ), BOPF or Enterprise Search ( @Search ). If that framework never reads the view, they do nothing.

View-level annotations

@EndUserText.label: 'Purchase order header'

@AccessControl.authorizationCheck: #CHECK

@Metadata.allowExtensions: true

define view entity ZC_PurchaseOrder ...

• @EndUserText.label : the description users and tools see; it works on fields too.

• @AccessControl.authorizationCheck: #CHECK : ABAP SQL applies the rules of an access control (DCL) object written with define role ; without a role you only get a warning at activation. Keep #NOT_REQUIRED for data with nothing to protect.

• @Metadata.allowExtensions: true : lets the UI annotations move to a metadata extension.

• @Analytics.dataCategory : #FACT for transaction data, #DIMENSION for master data, #CUBE for the central reporting view that links facts to their dimensions.

• @AbapCatalog.sqlViewName : older define view syntax only, where it names the generated SQL view.

Field-level annotations

Semantics

@Semantics.amount.currencyCode: 'Currency'

NetAmount,

Currency,

@Semantics.quantity.unitOfMeasure: 'OrderUnit'

OrderQuantity,

OrderUnit,

Each amount points to its currency field and each quantity to its unit, so decimals and units display correctly. @ObjectModel.text.element: ['SupplierName'] on a supplier ID shows the name next to the code.

Fiori elements (UI)

• @UI.lineItem: [{ position: 10 }] : a column in the list report table.

• @UI.selectionField: [{ position: 10 }] : a filter field above the table, such as PO number.

• @UI.identification: [{ position: 10 }] : a field in the object page's identification group, shown through a facet of type #IDENTIFICATION_REFERENCE .

• @UI.headerInfo (view level): the object's names, e.g. typeName: 'Purchase Order' , typeNamePlural: 'Purchase Orders' .

Analytics

@Aggregation.default: #SUM on a measure such as sales amount makes reports total it. Older views use @DefaultAggregation for this.

Move UI annotations to a metadata extension

Thirty @UI lines make a view hard to read. Create a metadata extension in ADT ( New > Other ABAP Repository Object > Core Data Services > Metadata Extension ) and keep them there:

@Metadata.layer: #CUSTOMER

annotate entity ZC_PurchaseOrder with

{

@UI.lineItem: [{ position: 10 }]

@UI.selectionField: [{ position: 10 }]

PurchaseOrder;

}

Associations and compositions are not annotations: declare them in the view with association [0..*] to ... or, in a RAP root view, composition [0..*] of ... .

Key takeaways

• ABAP annotations act at activation and on ABAP SQL access; framework ones only when their framework reads the view.

• Give every amount a currency and every quantity a unit with @Semantics .

• Use #CHECK together with a DCL role for business data.

• Keep @UI annotations in a metadata extension.

Want to practice annotations on real Fiori and RAP scenarios with a trainer? See our SAP ABAP Development course .