Day 7: CDS + OData Integration + Deep Dive: UI5 Fiori Annotations
Day 7: CDS + OData Integration + Deep Dive: UI5 Fiori Annotations
@OData.publish annotation
Service Activation: /IWFND/MAINT_SERVICE
URI Testing, $metadata, $expand, $filter
Deep Dive: UI5 Fiori Annotations
Tasks:
Expose CDS via OData
Fetch data in browser using URI
✅ 1. What is CDS + OData Integration?
CDS (Core Data Services) views in ABAP can be directly exposed as OData services. This allows frontend applications (e.g., SAP Fiori) to consume backend data over HTTP in a RESTful manner.
Why?
Enable Fiori/UI5 apps.
Minimize custom Gateway code.
Automatically generate metadata and entities.
✅ 2. @OData.publish: true – Explanation and Example
Annotation: @OData.publish: true
Purpose: Automatically creates an OData service from the CDS view.
Example:
@AbapCatalog.sqlViewName: 'ZC_CUSTOMERS'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Customer Consumption View'
@OData.publish: true
define view ZC_Customer as select from I_Customer
{
key Customer,
FirstName,
LastName,
Country
}
➡️ This will generate a service: ZC_CUSTOMER_CDS.
✅ 3. Service Activation – Step-by-Step using /IWFND/MAINT_SERVICE
Go to transaction /IWFND/MAINT_SERVICE.
Click Add Service.
System Alias: Usually LOCAL.
Search for Technical Service: ZC_CUSTOMER_CDS.
Click Add Selected Services.
Assign to a package / local object.
Assign a Catalog and click Continue.
Service is now active.
✅ 4. URI Testing – $metadata, $expand, $filter
After activation, test using:
✅ Metadata:
/sap/opu/odata/sap/ZC_CUSTOMER_CDS/$metadata
Returns XML with the structure of your entity.
✅ Filter:
/sap/opu/odata/sap/ZC_CUSTOMER_CDS?$filter=Country eq 'IN'
Fetches customers from India.
✅ Expand:
If associations exist:
/sap/opu/odata/sap/ZC_SALESORDER_CDS?$expand=_Items
✅ 5. Create VDM-Style CDS + OData with Authorization + UI Annotations
๐ท Step 1: Basic View
@AbapCatalog.sqlViewName: 'ZB_SALESORD'
@EndUserText.label: 'Basic Sales Order View'
define view entity ZB_SalesOrder as select from vbak
{
key vbeln,
erdat,
kunnr
}
๐ท Step 2: Composite View
@AbapCatalog.sqlViewName: 'ZJ_SALESORD'
@EndUserText.label: 'Composite Sales Order View'
define view entity ZJ_SalesOrder as select from ZB_SalesOrder
association [0..1] to I_Customer as _Customer
on $projection.kunnr = _Customer.Customer
{
key vbeln,
erdat,
kunnr,
_Customer
}
๐ท Step 3: Consumption View with OData, Authorization & UI Annotations
@AbapCatalog.sqlViewName: 'ZC_SALESORD'
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales Order Consumption View'
@OData.publish: true
define view entity ZC_SalesOrder as select from ZJ_SalesOrder
{
@UI.lineItem: [{ position: 10 }]
@UI.selectionField: [{ position: 10 }]
key vbeln,
@UI.lineItem: [{ position: 20 }]
erdat,
@UI.lineItem: [{ position: 30 }]
kunnr,
_Customer
}
๐ท Step 4: DCL Object – Restrict by user
define role ZC_SalesOrderAuth {
grant select on ZC_SalesOrder
where kunnr = SESSION_CONTEXT('CDS_CLIENT');
}
(Replace with real logic as per requirement.)
✅ 6. Fetch Data in Browser using URI
Once the service is active and metadata is validated:
Open browser.
URL:
https://<hostname>/sap/opu/odata/sap/ZC_SALESORDER_CDS/
Use Examples:
Get all records: ZC_SALESORDER_CDS
Filter by KUNNR: ZC_SALESORDER_CDS?$filter=kunnr eq '1000001'
Expand Customer: ZC_SALESORDER_CDS?$expand=_Customer
✅ Summary: What we’ve achieved
๐ Deep Dive: Fiori UI Annotations for CDS
๐ Goal:
Expose business logic via CDS views and directly render it in Fiori Elements using UI Annotations, enabling List Reports, Object Pages, Analytical Dashboards, Smart Filters, Charts, etc.
๐ฐ 1. UI Annotation Basics
๐ 2. Most Important Annotations (Real-Time Usage)
๐ 3. Deep Dive Topics Must Cover for UI5
✅ a) UI Facets and Field Groups
Facets = Tabs or Sections in Fiori Object Page
Field Groups = Group of fields inside a facet
Why? Improves readability and UX on Object Pages
@UI.facet: [{
id: 'Header',
label: 'Order Info',
type: #IDENTIFICATION_REFERENCE,
targetQualifier: 'OrderDetails'
}]
@UI.fieldGroup: [ { qualifier: 'OrderDetails', label: 'Order Detail Section' } ]
✅ b) Smart Filters with Selection Fields
Used for filtering in Fiori List Reports.
@UI.selectionField: [{ position: 10 }]
key salesOrderId : abap.numc(10);
✅ c) Data Points and KPI Cards (Object Page or Overview Page)
@UI.dataPoint: {
value: 'grossAmount',
title: 'Total Order Value',
criticality: 'orderCriticality'
}
grossAmount: abap.curr(16,2);
✅ d) Smart Charts
@UI.chart: {
chartType: #COLUMN,
dimensions: ['customerName'],
measures: ['netAmount'],
description: 'Sales per Customer'
}
๐ง 4. Advanced: UI Presentation Variants
Used to structure visual behavior in complex apps
@UI.presentationVariant: [{
sortOrder: [ { by: 'createdAt', direction: #DESC } ],
requestAtLeast: [ 'salesOrderId', 'customerName', 'createdAt' ]
}]
๐ 5. Other Useful UI Annotations
๐ 6. Practical Scenarios to Implement
You should try building these using CDS with UI annotations:
✅ 7. OData Exposure with UI Annotations
@OData.publish: true
define view ZI_SalesOrder
as select from ZSalesOrder {
key salesOrderId,
@UI.lineItem: [{ position: 10, label: 'Customer' }]
@UI.selectionField: [{ position: 1 }]
customerName
}
Then expose it via /IWFND/MAINT_SERVICE to make it accessible to Fiori.
๐งช 8. Testing Your Annotations
Once exposed:
Open Fiori Elements List Report App
Check filters, table columns, and object page sections
Adjust annotations as needed using Live Preview in ADT
๐ Summary
Day 8: AMDP Basics
What is AMDP?
Syntax and structure
Use of SQLScript in methods
Class creation with interface IF_AMDP_MARKER_HDB
Hands-on:
Create a basic AMDP class with SELECT logic
Comments
Post a Comment