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

CDS Annotations Part 4: Metadata Extensions — Separating UI from the Data Model

Preview · a free account unlocks the full lesson

Key takeaway

Separate UI from the data model with metadata extensions: syntax, allowed annotations, layers and precedence, and how to organize extensions for several apps on the same business object.

In this lessonShow sections

Visual overview

CDS Annotations Part 4: Metadata Extensions — Separating UI from the Data Model — learning sheetFlow: Add @Metadata.allowExtensions: true to ZC_PurchReq and ZC_PurchReqItem → Right-click the projection → New → Metadata Extension; choose layer #CUSTOMER → Move all @UI annotations from the view into the extension → Activate; check the preview — the UI must look the same. Key ideas: WHY METADATA EXTENSIONS; SYNTAX; ENABLING; LAYERS AND PRECEDENCE. Watch out: Not every annotation is allowed in a metadata extension — semantics stay in the view.ERPClimb.com / RAP / LESSON 4/5 / LEARNING SHEETCDS Annotations Part 4: Metadata Extensions — SeparatingUI from the Data Model1 · HOW IT FLOWS1Add@Metadata.allowExtensions:true to…2Right-click theprojection → New→ Metadata…3Move all @UIannotations fromthe view into…4Activate; checkthe preview —the UI must look…2 · KEY IDEAS EXPLAINEDWhy Metadata ExtensionsThe data model (fields, keys, associations,semantics) changes rarely.The UI (columns, positions, labels, sections)changes often.SyntaxOne metadata extension per layer for a givenentity; the file name is freely chosen(convention: same name as the view).You list elements by name, followed by asemicolon, with annotations in front.EnablingThe annotated view needs@Metadata.allowExtensions: true in its header.Without it, the extension is ignored (with a…Layers And PrecedenceSeveral extensions in different layers canannotate the same view. For the same annotation,the higher layer wins:3 · REMEMBER · WATCH OUTRememberA metadata extension (annotate entity … with) adds annotations to aview in a separate object.The view must allow it: @Metadata.allowExtensions: true.Layers decide precedence: #CUSTOMER > #PARTNER > #INDUSTRY >#LOCALIZATION > #CORE.!Watch outNot every annotation is allowed in ametadata extension — semantics stayin the view.4 · IN A REAL PROJECTA company used an SAP-delivered Fiori app but needed different column order and two extra filters. The firstidea was to copy the SAP CDS views into Z-views — which would have meant maintaining copies forever and losingSAP updates. Instead, a metadata extension in layer #CUSTOMER on the released consumption view changed…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

A metadata extension, declared with "annotate entity … with," adds annotations to a view from a separate object, which is what keeps the data model clean. For this to work, the view itself must allow it via @Metadata.allowExtensions: true. When multiple extensions annotate the same view, layers decide precedence, in order: #CUSTOMER, then #PARTNER, then #INDUSTRY, then #LOCALIZATION, then #CORE. Not every annotation is allowed inside a metadata extension — annotations that define actual semantics stay in the view itself.

Part 3 wrote the UI annotations themselves; this part explains the object that holds them, and why it keeps the data model clean.

The reasoning for metadata extensions comes down to how often things change. The data model — fields, keys, associations, semantics — changes rarely, while the UI — columns, positions, labels, sections — changes often. Keeping UI annotations in a separate object means UI changes never touch the view, views stay readable, different teams can work on each in parallel, and UI changes don't require re-activating dependent views.

The syntax looks like this:

@Metadata.layer: #CUSTOMER
annotate entity ZC_PurchReq with

{

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

RequestID;

}

There's one metadata extension per layer for a given entity, and the file name itself is freely chosen, though convention keeps it the same as the view's name. Elements are listed by name, followed by a semicolon, with their annotations placed in front; header-level annotations, such as @UI.headerInfo, go before "annotate entity".

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.