Day 5: CDS UI Annotations (Fiori-ready CDS)
Day 5: CDS UI Annotations (Fiori-ready CDS)
UI annotations: @UI.lineItem, @UI.selectionField
Field Groups and Facets
Search annotations, Smart Filter setup
CDS View Extension
All annotations discussed so far
Hands-on:
Build CDS with Smart Filter support
Test in WebIDE or Business Application Studio
๐น 1. What Are CDS UI Annotations?
CDS UI Annotations are metadata tags used in a CDS view to describe how the data should be presented in a Fiori app. They control UI behavior—like which fields show in the table, which fields are searchable, editable, or grouped—and enable automatic UI generation.
✅ Why important?
They eliminate the need for separate UI coding by guiding Fiori Elements to build your UI dynamically.
๐น 2. Why Use UI Annotations?
✅ Annotations allow Fiori to “read” your CDS view and render UI automatically.
๐น 3. Important UI Annotations and Their Use
✅ @UI.lineItem - @UI.lineItem: [{ position: 10 }]
Displays a field as a column in a Fiori List Report table.
✅ @UI.selectionField - @UI.selectionField: [{ position: 20 }]
Marks a field to appear as a filter in the Smart Filter Bar.
✅ @UI.identification - @UI.identification: [{ position: 10 }]
Used in the Object Page header.
✅ @UI.facet and @UI.fieldGroup
Used to group fields in an Object Page for better UX.
๐น 4. Example: Fiori-ready CDS with UI Annotations
@AbapCatalog.sqlViewName: 'ZUI_CDS_ORDR'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Sales Order with UI Annotations'
define view entity ZUI_SalesOrder
as select from I_SalesOrder as so
association [0..1] to I_Customer as _Customer
on so.BuyerParty = _Customer.Customer
{
@UI.lineItem: [{ position: 10 }]
@UI.selectionField: [{ position: 10 }]
key so.SalesOrder,
@UI.lineItem: [{ position: 20 }]
@UI.selectionField: [{ position: 20 }]
so.SalesOrderType,
@UI.lineItem: [{ position: 30 }]
@UI.selectionField: [{ position: 30 }]
so.SalesOrganization,
@UI.lineItem: [{ position: 40 }]
@UI.selectionField: [{ position: 40 }]
so.TotalNetAmount,
@UI.lineItem: [{ position: 50 }]
_Customer.CustomerName
}
➡️ This CDS, when exposed via OData and used in a Fiori List Report, automatically builds a table with filters and column headers.
๐น 5. What Are Field Groups & Facets?
✅ @UI.facet
Used to create logical groups of fields (like tabs or sections in Object Page).
✅ @UI.fieldGroup
Defines a group of fields shown together under a facet.
@UI.facet: [
{ id: 'General', type: #IDENTIFICATION_REFERENCE, label: 'General Info', position: 10 }
]
@UI.fieldGroup: [{ groupId: 'General', position: 10 }]
@UI.identification: [{ position: 10 }]
so.SalesOrder
๐น 6. Search Annotations & Smart Filter Setup
To improve search experience:
✅ @Search.defaultSearchElement
This marks a field as primary search field in global search (Ctrl+F).
@Search.defaultSearchElement: true
@UI.lineItem: [{ position: 10 }]
CustomerName
✅ @Search.fuzzinessThreshold - @Search.fuzzinessThreshold: 0.8
Controls fuzzy search behavior.
๐น 7. CDS View with All Key UI Annotations (Full Example)
@AbapCatalog.sqlViewName: 'ZSO_UI_FULL'
@EndUserText.label: 'Sales Order - Full UI Demo'
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view entity ZUI_FullSalesOrder
as select from I_SalesOrder as so
association [0..1] to I_Customer as _Customer
on so.BuyerParty = _Customer.Customer
{
@UI.lineItem: [{ position: 10 }]
@UI.selectionField: [{ position: 10 }]
@UI.identification: [{ position: 10 }]
@Search.defaultSearchElement: true
key so.SalesOrder,
@UI.lineItem: [{ position: 20 }]
@UI.selectionField: [{ position: 20 }]
@UI.identification: [{ position: 20 }]
so.SalesOrderType,
@UI.lineItem: [{ position: 30 }]
@UI.selectionField: [{ position: 30 }]
@UI.identification: [{ position: 30 }]
so.SalesOrganization,
@UI.lineItem: [{ position: 40 }]
@UI.selectionField: [{ position: 40 }]
so.TotalNetAmount,
@UI.lineItem: [{ position: 50 }]
@UI.identification: [{ position: 50 }]
_Customer.CustomerName
}
✅ Summary: When & Why to Use CDS UI Annotations
๐น 8. CDS View Extension (Enhancement)
✅ What Is It?
CDS View Extensions allow you to add fields or annotations to existing CDS views without modifying the original view.
This supports the SAP Clean Core principle — allowing you to extend views without touching standard SAP or base custom views.
๐ง Why Do We Use It?
๐ง Syntax
extend view entity ZI_SalesOrderParam with ZI_SalesOrderParam_Extension
{
vbak.vbtyp as SalesDocType,
vbak.vkgrp as SalesGroup
}
๐ ️ Step-by-Step Implementation
Let’s enhance the CDS ZI_SalesOrderParam (created above) with two extra fields: Sales Document Type and Sales Group.
✅ Step 1: Create Extension in ADT
Package: ZCDS_TRAINING
Name: ZI_SALESORDERPARAM_EXT
✅ Step 2: Add Code
@EndUserText.label: 'Extension for Sales Order Param CDS'
extend view entity ZI_SalesOrderParam with ZI_SalesOrderParam_Ext
{
vbak.vbtyp as SalesDocType,
vbak.vkgrp as SalesGroup
}
✅ Note:
The original view (ZI_SalesOrderParam) must include vbak in the FROM clause.
You can also add annotations in the extension like @UI.lineItem, etc.
✅ Step 3: Activate & Preview
Now when you do Data Preview on ZI_SalesOrderParam, the extra fields SalesDocType and SalesGroup are included in the result set.
๐งช UI Extension Use Case
extend view entity ZI_SalesOrderParam with ZI_SalesOrderParam_UI
{
@UI.lineItem: [{ position: 10 }]
vbak.vbtyp as SalesDocType,
@UI.selectionField: [{ position: 20 }]
vbak.vkgrp as SalesGroup
}
๐ CDS Annotations Overview from Day 1 - 4
Annotations in CDS are metadata tags that define semantics, behaviors, and UI characteristics of the CDS views. They help expose CDS views properly in analytics, OData, or UI5 apps.
๐น 1. @AbapCatalog Annotations
✅ Example:
@AbapCatalog.sqlViewName: 'ZVBAKBASIC'
๐น 2. @EndUserText Annotations
✅ Example:
@EndUserText.label: 'Sales Order Basic View'
๐น 3. @UI Annotations
Used for UI purposes (Fiori Elements, etc.)
✅ Example:
@UI.headerInfo: {
typeName: 'Sales Order',
typeNamePlural: 'Sales Orders',
title: { type: #STANDARD, value: 'SalesOrder' }
}
๐น 4. @Analytics Annotations
Used to enable the CDS view for analytical reporting tools like RSRT or SAP Analytics Cloud.
✅ Example:
@Analytics.query: true
๐น 5. @Semantics Annotations
These annotations indicate unit, currency, and value types, essential for analytical views and correct field formatting.
✅ Example:
@Semantics.currencyCode: true
Currency,
@Semantics.amount.currencyCode: 'Currency'
NetValue,
๐น 6. @ObjectModel Annotations
Used for controlling OData exposure and UI behavior in VDM or RAP.
✅ Example:
@ObjectModel.text.element: 'Country'
CountryName
๐น 7. @AccessControl Annotations (Used in Advanced cases)
✅ Example:
@AccessControl.authorizationCheck: #CHECK
Comments
Post a Comment