This post summarizes the most common annotations that are required to build a RESTful Application Programming Service in ABAP. ABAP CDS are written in Data Definition Language (DDL).

These annotations are broadly categorized into two types.

ABAP CDS – ABAP Annotations

These annotations are evaluated by ABAP runtime environment.

  • AbapCatalog Annotations
  • AccessControl Annotations
  • ClientHandling Annotations
  • EndUserText Annotations
  • Environment Annotations
  • MappingRole Annotations
  • Metadata Annotations

AbapCatalog Annotations

  • AbapCatalog.sqlViewName
    • CDS view, name of the database view
    • Any 16 character value (starting with Z for custom objects)
    • Only required for CDS View
  • AbapCatalog.sqlViewAppendName
    • CDS view extension, name of the append view
    • Any 16 character value (starting with Z for custom objects)
    • Required when CDS view is extended
  • AbapCatalog.viewEnhancementCategory[ ]
    • CDS view, specifies how the view can be extended using CDS view extensions
    • #GROUP_BY
      #NONE
      #PROJECTION_LIST
      #UNION

AccessControl Annotations

  • AccessControl.authorizationCheck
    • CDS access control, specifies implicit access control
    • #CHECK
      #MANDATORY
      #NOT_ALLOWED
      #NOT_REQUIRED
      #PRIVILEGED_ONLY
    • Default value is #NOT_REQUIRED
    • For test RAP services use the default value #NOT_REQUIRED

ClientHandling Annotations

  • ClientHandling.type
    • Specifies client dependency
    • This is not a mandatory but can be used for DDIC based views and Table functions
    • #CLIENT_DEPENDENT
      #CLIENT_INDEPENDENT
      #INHERITED
    • Default value is #INHERITED

EndUserText Annotations

  • EndUserText.label
    • Short text
    • The label automatically comes from the data element, but where the basic types is used the label is useful
  • EndUserText.quickInfo
    • Tooltip information

Environment Annotations

  • Environment.systemField
    • Environment, assigns an ABAP system field
    • #CLIENT
      #SYSTEM_DATE
      #SYSTEM_LANGUAGE
      #SYSTEM_TIME
      #USER
      #USER_DATE
      #USER_TIMEZONE
    • These fields can be used to assign default system variable values to parameters or in the list

MappingRole Annotations

  • MappingRole
    • Access control, specifies the assignment of a CDS role to users
    • Default value is true
    • For test services or learning purpose, ignore this annotation

Metadata Annotations

  • Metadata.allowExtensions
    • Specifies extensibility using metadata extensions
    • Default value is true
  • Metadata.ignorePropagatedAnnotations
    • Specifies how propagated annotations are evaluated
    • Default value is true
  • Metadata.layer
    • Specfies layer in CDS metadata extension
    • #CORE
      #CUSTOMER
      #INDUSTRY
      #LOCALIZATION
      #PARTNER
    • Usually, we use value #CUSTOMER

Framework-Specific Annotations

  • AccessControl Annotations
  • Consumption Annotations
  • ObjectModel Annotations
  • OData Annotations
  • Search Annotations
  • Semantics Annotations
  • UI Annotations
  • Aggregation Annotations

These annotations are exposed to OData Service.

AccessControl Annotations

Define how the authorization check for a CDS entity is executed.

  • AccessControl.authorizationCheck
    • Defines the behavior of the authorization check.
    • #NOT_REQUIRED

      During the runtime, an authorization check is executed if a DCL role exists. During development, no warning occurs when activating the entity.

      #NOT_ALLOWED

      During the runtime, no authorization check is executed. During development, a warning occurs if a r

      #CHECK

      During the runtime – an authorization check is executed if DCL role exists. During development, a warning occurs if a developer activates the entity and no DCL role exists for the entity. This value is the default value.

Consumption Annotations

Define a specific behavior that relates to the consumption of CDS content through domain-specific frameworks.

Filter

  • Consumption.filter.defaultValue
    • Specifies a default value for a filter of a view element.
  • Consumption.filter.defaultValueHigh
    • This annotation is used in combination with defaultValue to specify a default interval for a filter of a view element.
  • Consumption.filter.hidden
    • Specifies that the filter is hidden
  • Consumption.filter.mandatory
    • Enforces a user to enter a value even if a default value exists.
  • Consumption.filter.multipleSelections
    • Several values can be entered on the filter input
  • Consumption.filter.selectionType
    • Defines how values can be entered
    • #SINGLE. #INTERVAL, #RANGE, #HIERARCHY_NODE are the possible values

Element / Property

  • Consumption.hidden
    • Prevents fields from being exposed by OData
  • Consumption.defaultValue
    • Action importing parameters to define default values for the action consumption via UI consumption.
  • Consumption.semanticObject
    • Used for interoperability across applications
    • The semantic semantic object that is defined in the Fiori Launchpad must be specified as the value.
    • SAP Fiori has introduced the concept of intent-based navigation, whereby an intent is a combination of <semanticObject> <action>. A semanticObject annotation is used in SAP Fiori UIs to dynamically derive navigation targets for the annotated view as a source.

Value Help

  • Consumption.valueHelpDefinition.distinctValues
    • Specifies whether the value help result list shall only contain distinct values
  • Consumption.valueHelpDefinition.entity[element, name]
    • Name : Specifies the entity which contains the element that provides the value help
    • Element : element in the entity referenced in name that provides the value help 
  • Consumption.valueHelpDefinition.label
    • Contains a language-dependent text that is used to label the value list
  • Consumption.valueHelpDefinition.useForValidation
    • Marks value help that shall be used for validation of user input
  • Consumption.ranked
    • This annotation enables search results in value help views to be automatically sorted by search score.

ObjectModel Annotations

  • ObjectModel.filter.enabled
    • Sets entity element as filterable or non-filterable according to the value true or false.
  • ObjectModel.sort.enabled
    • Sets entity element as sortable  or non-sortable according to the value true or false.
  • ObjectModel.text.association
    • Defines the associated view, which provides textual descriptions.
  • ObjectModel.text.element[ ]
    • Connects a field with its descriptive language-independent texts.
  • ObjectModel.usageType.sizeCategory
    • The sizeCategory is used to support the resource consumption within HANA.
    • S: Expected number of rows is < 1.000
    • M: Expected number of rows is is between 1.000 and 99.999
    • L: Expected number of rows is between 100.000 and 9.999.999
    • XL: Expected number of rows is between 10.000.000 and 99.999.999
    • XXL: expected number of rows is >= 100.000.000
  • ObjectModel.query.implementedBy:
    • References the query implementation class for the unmanaged query.
  • ObjectModel.virtualElementCalculatedBy:
    • References the calculation class for the annotated virtual element.

OData Annotations

OData annotations define OData specific properties.

  • OData.action
    • Denotes the external name of an action
  • OData.entitySet.name
    • Denotes the external name of the entity set
  • OData.entityType.name
    • Denotes the external name of the entity type
  • OData.etag
    • Declare ETags in behavior definitions. As per SAP documentation – this annotation should not be used

Search Annotations

  • Search.searchable
    • Defines if a CDS entity is generally relevant for search scenarios.
    • Boolean (true, false) values can be assigned
  • Search.defaultSearchElement
    • Specifies that the element is to be considered in a freestyle search where no columns are specified.
    • Boolean (true, false) values can be assigned
  • Search.ranking
    • Specifies how relevant the values of an element are for ranking
    • HIGH – The element is of high relevancy
    • MEDIUM – The element is of medium relevancy
    • LOW – Although the element is relevant for freestyle search, a hit in this element has no real significance on the rank
  • Search.fuzzinessThreshold
    • Specifies the least level of fuzziness
    • The value format is Decimal (3,2) and the value is between 0 to 1. For example, 0.8
    • A value between 0.7 and 0.99 would be most useful. 1 means exact match.

Semantics Annotations

These are used by the core engines for data processing and data consumption.

  • Semantics.address.type []
    • #HOME – Home address
    • #WORK – Work address
    • #PREF – Preferred address (default)
    • OTHER – other address
  • Semantics.address.city, Semantics.address.country, Semantics.address.number, Semantics.address.postBox Semantics.address.region, Semantics.address.zipCode
    • These annotations denote that the field is part of address and means as per the annotation name
  • Semantics.amount.currencyCode
    • Specifies the currency code field from the projection list
  • Semantics.currencyCode
    • Specifies that the field is a currency
  • Semantics.quantity.unitOfMeasure
    • Specifies UOM field from the projection list
  • Semantics.unitOfMeasure
    • Specifies that the field is a Unit of Measure
  • Semantics.calendar.dayOfMonth, Semantics.calendar.dayOfYear, Semantics.calendar.halfyear, Semantics.calendar.month, Semantics.calendar.quarter, Semantics.calendar.week, Semantics.calendar.year
    • The value of the annotated field encodes accordingly.
  • Semantics.dateTime
    • Tags a field containing a date with time value.
  • Semantics.language
    • Identifies a language field.
  • Semantics.systemDateTime.createdAt, Semantics.systemDateTime.lastChangedAt, Semantics.systemDateTime.LocalInstanceLastChangedAt, Semantics.user.createdBy, Semantics.user.lastChangedBy
    • These can be used to annotate change logging and etag fields within entity

UI Annotations

There are too many UI annotations which can not be covered here. Refer SAP Documentation for all the annotations

  • UI.selectionField
    • Allow filtering
    • UI.selectionField.position – specify the order of selection fields
  • UI.lineItem
    • Represent an ordered collection of data fields on a list or a table
    • UI.lineItem.position – specify the order
    • UI.lineItem.importance – HIGH, MEDIUM, LOW
      • The columns that need to be displayed always, get importance HIGH and will be displayed even when the app is rendered on a smaller screen
    • UI.lineItem.label – contains a language-dependent text.
  • UI.identification
    • Represent an ordered collection of specific data fields on object page
    • UI.identification.position, UI.identification.importance, UI.identification.label are similar to UI.lineItem however they work on the object page instead of list
  • UI.facet
    • Sets up how the sections are displayed on UI
    • id – the identifier of the facet
    • purpose – This annotation specifies the purpose of a facet
      • Possible values are – STANDARD, HEADER, QUICK_VIEW, QUICK_CREATE, FILTER
      • default: STANDARD;
    • parentId – identifies the parent facet
    • Purpose and parentId both can not be specified for one facet
    • type – specifies the concrete type of the facet
      • COLLECTION
      • ADDRESS_REFERENCE
      • BADGE_REFERENCE
      • CHART_REFERENCE
      • CONTACT_REFERENCE
      • DATAPOINT_REFERENCE
      • HEADERINFO_REFERENCE
      • IDENTIFICATION_REFERENCE
      • LINEITEM_REFERENCE
      • STATUSINFO_REFERENCE
      • URL_REFERENCE

Aggregation Annotations

With this annotation, the aggregation behavior of elements is specified. Elements without default aggregation or with Aggregation.default: #NONE will not be aggregated and will be used in GROUP BY 

  • Aggregation.default
    • This is only allowed in views with dataCategory: #CUBE, #FACT, #DIMENSION.
    • Default value is #NONE
  • Aggregation.exception
    • Exception aggregation is always performed in addition to default aggregation, which must not be equal to the #NONE. This means that data is first aggregated through the default aggregation grouped by the reference element and then aggregated with the exception aggregation.

Note that this is just a summary and there are too many other annotations. Please refer below link for examples and more explanation.

Reference: https://help.sap.com/docs/btp/sap-abap-restful-application-programming-model/cds-annotations

Visit ABAP RESTful Application Programming Model to explore all articles on ABAP RAP Model.


If you like the content, please subscribe…

Join 4,016 other subscribers

Discovering ABAP YouTube Channel