Using the Core Data Services (CDS) View

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Describe the usage of CDS view

The Core Data Services (CDS) View

The ABAP Core Data Services (ABAP CDS) are the platform-independent implementation of the general CDS concept for AS ABAP. The ABAP CDS makes it possible to define semantic data models on the standard AS ABAP database. Unlike the SAP HANA-specific variant HANA CDS, the ABAP CDS are independent of the database system.

The entities of the models defined in ABAP CDS provide enhanced access functions compared with existing database tables and views defined in ABAP Dictionary, making it possible to optimize Open SQL-based applications. This is particularly clear when an AS ABAP uses an SAP HANA database, since its in-memory characteristics can be implemented in an optimum manner.

Note

The purpose of this lesson is to let you have basic understand of CDS.

For detailed knowledge of CDS, please refer to course S4D430.

Basic Syntax of CDS

A basic CDS defines a view. The definition of CDS uses SQL like syntax.

Annotations for CDS Views

In the figure below we use ABAP annotations and UI annotations. As an example, the ABAP annotations @OData.publish:true ensures that an OData service is created when the CDS view is activated. The annotations @UI.lineItem ensures that a column is created.

CDS annotations are extra information to describe the data. They let the consumer of CDS view know how to use data from the CDS view.

Annotations are grouped according to usage. The figure above shows the most relevant groups of association for SAP Fiori elements.

To have full knowledge of CDS annotations, you can access the CDS annotation document. Search for ABAP Programming Model for SAP Fiori on Sap Help Portal.

Follow these steps:

  1. Go to SAP Help.
  2. Search "ABAP  Programming Model for SAP Fiori" and press Enter.
  3. Choose the correct result according your Kernel version.
  4. Click "Reference" on left bottom of the screen.

Annotation Syntax: Structure Type

If an annotation term represents a structure, two options are available for writing the annotation.

Let's explore!

Both syntax have same meaning and can be used in combination, such as @UI.headerInfo.title: { value: 'SalesOrderID' }

If an annotation term represents an array, the only option is to use a JSON array.

Annotation Syntax: Array Type

Key features of this syntax are:

  • "{ }" represent a structure.
  • "[ ]" represent an array.
  • Use ":" to separate property name and its value.
  • Use "," to separate properties.
  • In most cases, each line should have a property called "qualifier" to identify it.

In some cases, a term is an array type, but most of its usage only has single line of record.

In this situation, you can use object style to simplify the input.

CDS Associations

A CDS view can define some associations. An association is a declaration of the relationship of views which can be consumed by itself or by the consumer of this CDS view.

Usually, you need to define some reusable CDS views, which define associations as a representation of the business entity. Then you can write a consumption CDS view, which uses the interface view as its data source, to consume the data and associations.

In the figure, interface View 1 has two associations connected to Interface View 3 and Interface View 2.

When consumption View 1 accesses data of interface View 1, it can do the following:

  • Access fields of Interface View 1.
  • Access fields of Interface View 2 through association 1 of interface View 1.
  • Expose Association 2 of Interface View 1 again, to let the consumer of this view have the ability to access fields of Interface View 3.

There are three main areas of an association. Let's look at each of them.

Save progress to your learning plan by logging in or creating an account