完整 UI 注释示例代码
ABAP RESTful 应用程序编程模型 › 开发 › 开发 UI 特定 › 定义元数据驱动的 UI 的 CDS 注释 › 完整 UI 注释示例代码
在 CDS 中使用 UI 注释的工作示例代码。
主要 CDS 视图的元数据扩展
Z_C_TRAVEL_R
展开以下代码示例以查看源代码
示例代码
@Metadata.layer: #CORE
@UI: { headerInfo: { typeName: 'Object Page - Title',
title: { value: 'TravelID' }, // Defines the value shown in title section
typeNamePlural: 'List Report - Table Header'
}
}
annotate view Z_C_TRAVEL_R with
{
// FACET SECTION
@UI.facet: [
// Header Facet (Object Page):
{ id: 'HeaderFacet',
purpose: #HEADER,
type: #FIELDGROUP_REFERENCE,
label: 'Object Page - Header Facet',
targetQualifier: 'HeaderItems', // Refers to lineItems with @UI.fieldGroup: [{qualifier: 'HeaderItems'}]
position: 10 },
// Body Facets (Object Page)
// Facet for chart - charts can only be displayed in facets
{ id: 'Chart1-ID', // Facet for our Chart with type "#CHART_REFERENCE"
purpose: #STANDARD,
type: #CHART_REFERENCE,
label: 'Chart facet',
targetQualifier: 'Chart1',
targetElement: '_Booking', // Specifies where the data is retrieved from
position: 1
},
// Facet 1 - Parent (collection) for Fieldgroup 1 and Fieldgroup 2
{ id: 'Facet1-ID',
type: #COLLECTION,
label: 'Facet 1 - Customer & Travel Data',
position: 10 },
// Facet for Fieldgroup 1 - nested inside Facet 1
{ id: 'Fieldgroup1-ID',
type: #FIELDGROUP_REFERENCE,
label: 'Fieldgroup 1 - Customer Data',
parentId: 'Facet1-ID', // Places this facet into 'Facet 1'
targetElement: '_Customer', // Specifies where the data is retrieved from - UI annotations must be defined in the respective target
targetQualifier: 'Fieldgroup1',
position: 10 },
// Facet for Fieldgroup 2 - nested inside Facet 1
{ id: 'Fieldgroup2-ID',
type: #FIELDGROUP_REFERENCE,
label: 'Fieldgroup 2 - Travel Data',
parentId: 'Facet1-ID', // Places this facet into 'Facet 1'
targetQualifier: 'Fieldgroup2', // No targetElement defined - Default target is the entity in which the facet is defined
position: 20 },
// Facet 2
{ id: 'Facet2-ID',
type: #LINEITEM_REFERENCE, // Facet shows the referenced items in a list report
label: 'Facet 2 - Bookings',
targetQualifier: 'Facet2',
position: 20,
targetElement: '_Booking'},
// Facet 3
{ id: 'Facet3-ID',
purpose: #STANDARD,
type: #IDENTIFICATION_REFERENCE, // Refers to elements annotated with '@UI.identification' in the element list below
label: 'Facet 3 - Overview and Comments',
position: 30 }
]
// ELEMENT LIST
@UI: { lineItem: [ { position: 10,
importance: #HIGH } ],
identification: [ { position: 10 } ],
selectionField: [ { position: 10 } ],
fieldGroup: [ { qualifier: 'HeaderItems',
position: 10 } ] }
TravelID;
@UI: { lineItem: [ { position: 20,
importance: #HIGH,
label: 'Agency' } ],
identification: [ { position: 20,
label: 'Agency'} ],
selectionField: [ { position: 20 } ],
fieldGroup: [ { qualifier: 'HeaderItems',
position: 20 } ] }
AgencyID;
@UI: { lineItem: [ { position: 30,
importance: #HIGH,
label: 'Customer' } ],
identification: [ { position: 30,
label: 'Customer' } ],
selectionField: [ { position: 30 } ],
fieldGroup: [ { qualifier: 'Fieldgroup2',
position: 10 } ] }
CustomerID;
@UI: { lineItem: [ { position: 40,
label: 'Start of Travel' } ],
identification: [ { position: 40,
label: 'Start of Travel' } ],
fieldGroup: [ { qualifier: 'Fieldgroup2',
position: 20 } ] }
BeginDate;
@UI: { lineItem: [ { position: 50,
label: 'End of Travel',
importance: #MEDIUM } ],
identification: [ { position: 50,
label: 'End of Travel' } ],
fieldGroup: [ { qualifier: 'Fieldgroup2',
position: 10 } ] }
EndDate;
@UI: { hidden: true,
identification: [ { position: 80 } ] ,
fieldGroup: [ { qualifier: 'Fieldgroup2',
position: 10 } ] }
BookingFee;
@UI: { identification: [ { position: 60 } ] ,
fieldGroup: [ { qualifier: 'Fieldgroup2',
position: 10 } ],
dataPoint: { title: 'Total Price',
targetValueElement: 'TotalPrice' } }
TotalPrice;
@UI: { identification: [ { position: 70,
label: 'Comment' } ] ,
fieldGroup: [ { qualifier: 'Fieldgroup2',
position: 10 } ] }
Memo;
@UI: { lineItem: [ { position: 60,
importance: #HIGH },
{ type: #FOR_ACTION,
dataAction: 'set_status_booked',
label: 'Set to Booked' } ],
fieldGroup: [ { qualifier: 'Fieldgroup2',
position: 10 } ] }
Status;
}
客户的元数据扩展
Z_C_CUSTOMER_R
展开以下代码示例以查看源代码
示例代码
@Metadata.layer: #CORE
annotate view Z_C_CUSTOMER_R
with
{
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 05}]
Street;
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 10}] // Using gaps between position numbering for easier modification later on
CustomerID;
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 20}]
FirstName;
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 30}]
LastName;
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 40}]
Title;
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 50}]
PostalCode;
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 60}]
City;
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 70}]
CountryCode;
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 80}]
PhoneNumber;
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 90}]
EMailAddress;
/* Associations */
@UI.fieldGroup: [{qualifier: 'Fieldgroup1', position: 100}]
_Country;
}
预订的元数据扩展
Z_C_BOOKING_R
展开以下代码示例以查看源代码
示例代码
@Metadata.layer: #CORE
@UI.chart: [{
qualifier: 'Chart1', //refers to targetQualifier defined in chart facet in Z_C_TRAVEL_UI
title: 'Flight Prices of this Travel by Airline',
chartType: #COMBINATION_DUAL,
dimensions: [ 'AirlineID'],
measures: [ 'ConvertedFlightPrice', 'DistinctBookings'],
measureAttributes: [ {measure: 'ConvertedFlightPrice', role: #AXIS_1},
{measure: 'DistinctBookings', role: #AXIS_2} ],
dimensionAttributes: [ {dimension: 'AirlineID', role: #SERIES} ],
description: 'Chart shows flight prices of travel by the airlines used per each booking.'
}
]
annotate view Z_C_BOOKING_R with
{
@UI.lineItem:
[{ qualifier: 'Facet2',
position: 10,
label: 'Travel No.',
hidden: true }]
TravelID;
@UI.lineItem:
[{ qualifier: 'Facet2',
position: 20,
label: 'Booking No.' }]
BookingID;
@UI.lineItem:
[{ qualifier: 'Facet2',
position: 30,
label: 'Date of Booking' }]
BookingDate;
@UI.lineItem:
[{ qualifier: 'Facet2',
position: 40,
label: 'Customer' }]
CustomerID;
@UI.lineItem:
[{ qualifier: 'Facet2',
position: 50,
label: 'Airline' }]
AirlineID;
@UI.lineItem:
[{ qualifier: 'Facet2',
position: 60,
label: 'Connection No.' }]
ConnectionID;
@UI.lineItem:
[{ qualifier: 'Facet2',
position: 70,
label: 'Date of flight' }]
FlightDate;
@UI.lineItem:
[{ qualifier: 'Facet2',
position: 80,
label: 'Flight Price' }]
FlightPrice;
@UI.lineItem:
[{ qualifier: 'Facet2',
position: 90,
label: 'Currency' }]
CurrencyCode;
}
来源:SAP Help Portal · 2025 FPS02 (Oct 2026) · 中文为 SAP 官方机器翻译
← 图表类型 · 元数据驱动 UI 的更多选项 →