CDS Annotations Part 4: Metadata Extensions — Separating UI from the Data Model
Preview · a free account unlocks the full lesson
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 sectionsHide sections
Visual overview
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".
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.