Show TOC

Adding Metadata to Data ModelLocate this document in the navigation structure

This topic demonstrates how you can expand the syntax of the CDS view to include metadata with the aim of providing some additional list reporting capabilities.

Adding the List Title

You have the option to work with a title in your result list. For this, add the @UI.headerInfo annotation to the CDS view and specify the header information in singular form for a single instance (single sales order item) and in plural form for multiple instances of sales order items.

	@UI.headerInfo: { typeName: 'Sales Order Item', typeNamePlural: 'Sales Order Items' }
	define view ZDEMO_SALES_ORDER_ITEM_ADV as
	...
				

Preview:

List title – header information in plural form
Figure 1: List title – header information in plural form
Adding a Standard Search Filter

If a CDS view is annotated as @Search.searchable, the UI runtime automatically takes this is into consideration, so that no additional UI annotations are required to expose a standard search field. However, for a meaningful search, at least one field must be defined as the default search field by annotating this field as @defaultSearchElement: true. The search is then initiated solely effected by those fields that are defined as default search fields. In the listing below, the ProductCategory is defined as the default search field.

	@Search.searchable: true
	define view ZDEMO_SALES_ORDER_ITEM_ADV as
	...
	@Search.defaultSearchElement: true
	Item.product.category as ProductCategory,
	...
	
			

Preview:

To facilitate finding the desired data, you can provide the standard filter for the list reporting UI.
Figure 2: To facilitate finding the desired data, you can provide the standard filter for the list reporting UI.
Adding a Filter Bar for Field-Specific Selection

You can use the following UI annotations to enable specific elements for selection, for example, when providing a filter bar:

The first filter allows the end user to search for Sales Order IDs. As the second filter, the customer’s Company search field is defined, whereas the product Category should appear as the third filter. In addition, the Company field should be considered as the default search field in the standard search filter.

Note If an element is annotated as SelectionField and has a value-help, the value-help is exposed automatically to the UI. This is independent from the @Search.searchable annotation.
	
	@UI.selectionField.position: 10
	key Item.sales_order.sales_order_id 	 as SalesOrderID 
	...
	@UI.selectionField.position: 20
	@Search.defaultSearchElement: true
	@Search.fuzzinessThreshold: 0.7
	Item.sales_order.customer.company_name    as CustomerName,
	...
	@UI.selectionField.position: 30
	@Search.defaultSearchElement: true
	Item.product.category 			     as ProductCategory,
	...
							

Preview:

Filter bar with predefined position of search fields
Figure 3: Filter bar with predefined position of search fields
Positioning and Prioritizing UI Elements

Now you can specify which field should be displayed in the list report and at which position.

To define the order of fields in the UI, you can use the position property of dataField-like annotations. Only the positioning order is relevant, so you can use any decimal number as the value for the positioning property.

To define the priority of elements, you can use the importance property of dataField-like annotations. This information, in particular, is relevant for adaptive UIs. If an UI is displayed on a small screen, elements with low priority can automatically be hidden. To define importance, you can choose the following values:

  • #HIGH
  • #MEDIUM
  • #LOW
  • None (Default)

In the list, the Sales Order ID field should get a specific label (Sales Order) and be displayed at the first position within the result list.

	...
	@UI.lineItem: { importance: #HIGH, label: 'Sales Order', position: 10 }
	key Item.sales_order.sales_order_id as SalesOrderID,
	...
		
			

Life cycle status information should be displayed on the result list by default:

	@UI.lineItem.position: 40
	Item.sales_order.lifecycle_status as LifecycleStatus,
	...
				
							

The order of fields is continued with currency and both amount fields:

	@UI.lineItem.position: 50
	Item.currency_code    as CurrencyCode, 
   
	@UI.lineItem.position: 60
	Item.gross_amount     as GrossAmount, 
   
	@UI.lineItem.position: 70
	Item.net_amount       as NetAmount
	...
				

The customer’s Company name should also appear in the list:

	@UI.lineItem.position: 90
	Item.sales_order.customer.company_name as CustomerName,
	...
								

The product Category as last field in the list:

	@UI.lineItem.position: 100
	Item.product.category as ProductCategory,
	...
						

Preview:

Positioning of fields in the result list
Figure 4: Positioning of fields in the result list
Specifying Metadata for Currency Field

It is not required for the currency field to appear as a separate field in the result list. Therefore, the currency field should be hidden in the list and therefore not available for the personalization settings dialog. The currency code is displayed in connection with the amount data instead. This is implemented by the annotation @Semantics.currencyCode: true. The annotation @Semantics.amount.currencyCode: 'CurrencyCode' defines each amount element as a currency field.

The @DefaultAggregation: #SUM annotation is used for analytical capabilities: The annotated amount fields are specified as so-called measures, that is, fields that can be aggregated.

Note If no @DefaultAggregation annotation is assigned to an element, the engine assumes no aggregation takes place.
	...
	@Semantics.currencyCode: true
	@UI.hidden: true
	Item.currency_code    as CurrencyCode, 

	...   
	@DefaultAggregation: #SUM
	@Semantics.amount.currencyCode: 'CurrencyCode'
	Item.gross_amount     as GrossAmount, 

	
	...   
	@DefaultAggregation: #SUM
	@Semantics.amount.currencyCode: 'CurrencyCode'
	Item.net_amount       as NetAmount
	...
						

Preview:

The currency is displayed in connection with the amount data
Figure 5: Currency is displayed in connection with the amount data
Aggregated fields
Figure 6: The aggregated fields display the sum