ABAP CDS Views – all you need to know

ABAP CDS Views

Share This Post

You may have heard the term ABAP CDS Views, or perhaps you are curious what modern development on SAP S/4HANA system looks like?  

In this blog post Radek Chudziak, Senior Developer at Absoft, explains what ABAP CDS views are, why they were introduced by SAP and how they can act as a data provider to different kinds of applications.

–    What are ABAP CDS Views?

        ABAP Dictionary Views vs. ABAP CDS Views

        Why ABAP CDS Views? – Classic vs Code Pushdown approach

        Code Pushdown – Example

        Consumption of CDS Views

        The Power of Annotations

        System Requirements

        Development Environment

      ABAP CDS vs HANA CDS

What are ABAP CDS Views?

In a nutshell, ABAP CDS Views is an important technology for modern application development on SAP systems and should not be overlooked. They provide enhancements in terms of data modelling and enable improved performance when combined with SAP HANA database.

ABAP CDS Views allow developers to create semantically rich data models which the application services expose to UI clients. It is the central pillar of S/4HANA development and is used as the core technology in most of SAP’s programming models.

Whether it is ABAP Programming Model for SAP Fiori, ABAP RESTful Application Programming Model,  SAP Cloud Application Programming Model or S/4HANA Embedded Analytics CDS Views is the main technology used for data querying and modelling.

Created using an enhanced version of openSQL syntax, ABAP CDS Views reside in the application server (data dictionary) but process the logic in the database.

While the data in SAP is still physically stored in transparent tables, CDS Views are an abstraction layer on top of the tables for data modelling purposes. They understand the relationship between database tables and hide the complexity from the ABAP programmer.

A diagram showing how tables relate to the overall ABAP CDS View

ABAP Dictionary Views vs. ABAP CDS Views

If you are familiar with ABAP Dictionary views, then you can think of CDS Views as a much more sophisticated version.

ABAP Dictionary views just link database tables, whereas CDS views bring many more features. Such features include calculations, aggregations, more variations of table joins, and they can also be stacked with each other. The comparison is illustrated by the diagram below:

A diagram showing the process of moving ABAP Dictionary Views to ABAP CDS Views

Why ABAP CDS Views? – Classic vs Code Pushdown approach

The classic SAP development approach has been to keep the unnecessary load away from the database. Developers would select the required data from a database and do further processing and manipulation on the application server. The code would become complex (as its majority has been built for performance reasons) through the use of indexes and added no value to core business functions.

With the invention of SAP HANA database and consequent introduction of ABAP CDS Views this approach has changed. The new programming paradigm is called ‘code pushdown’ or “code to data”. The rule-of-thumb is to ‘do as much as possible in the database to get the best performance’.

And “as much as possible” means: all expensive calculations, aggregations and string operations should be done on the database level with only the resulting sets to be transferred to the application layer. SAP HANA database is optimised to complete such tasks. This leads to performance gains and reduction of the the complex application code. For comparison – huge amounts of data had to be transferred for processing with the classic approach. In some cases this could cause short dumps due to memory consumption limits.

SAP HANA is capable of aggregating on the fly. There is no need for pre-built aggregates and indexes since the data is organized using column stores. Also, in an S/4HANA system the data model has been simplified, by getting rid of tables necessary for aggregations and indexes.

The classic vs code pushdown (data centric approach) comparison can be represented by the following diagram:

A diagram displaying the classic approach and the data eccentric approaches to application programming models and databases

Code Pushdown – Example

So, what does ‘code pushdown’ really mean? I am using an example of a CDS View below to explain: 

Various lines of coding being highlighted

Apart from regular fields selection from database table SBOOK this CDS view:

  • Uses a cases statement, based on the value of CLASS field it will return a corresponding value: ‘Economy’, ‘Business’, ‘First’.
  • Does a currency conversion from source currency to USD using a built-in function
  • Calculates the difference between order date and flight date using a built-in function

In the classic approach, all these calculations and conversions would have been done on the application server in ABAP. With CDS Views it is possible to do so on the database level.

Consumption of CDS Views

CDS Views can be consumed in many ways as a data source. Whether it is well known ALV report using ALV with Integrated Data Access (IDA) or modern SAP Fiori application with the CDS view exposed using SAP Gateway in the oData format. You can also quickly build FIORI apps on top of CDS Views with SAP FIORI Elements templates. CDS Views also work very well with SAP’s analytical apps using analytics related annotations and analytical engine. Below is a simplified diagram of CDS Views consumption:

A simplified diagram of how CDS Views are processed for consumption

The Power of Annotations

As already mentioned, CDS views are created with openSQL which can be enriched with annotations. These annotations fall into different categories: semantic (used for S4HANA Embedded Analytics), analytical (used by analytical tools like Bex, Lumira), UI annotations (used for FIORI applications). The UI annotations are an interesting case. By marking the CDS view with relevant annotations and the use of SAP FIORI Elements we can generate a FIORI app without writing a single line of JavaScript code. The whole UI generation is driven by the CDS View and the UI annotations.

There are some drawbacks however, e.g. only certain floorplans are supported, and it is not as flexible as a freestyle SAPUI5 app. On the other hand, it is a great tool to quickly generate reports with filter bars. This is demonstrated by the illustration below. On the left-hand side you can see a CDS View with UI annotations and on the right-hand side is the generated FIORI app.

CDS View with UI annotations and on the right-hand side is the generated FIORI app

  • The search annotation enables a search dialogue
  • Annotation responsible for adding the Sales Order ID field in the selection dialog (filter bar)
  • Annotation which sets the position of the Sales Order ID field in the output table.

System Requirements

The runtime for CDS views is ABAP SAP NetWeaver stack. CDS Views are also database agnostic. This means that technically any SAP ERP system that runs on SAP NetWeaver 7.4 SP05 can make use of CDS Views. Having said that – this is not always recommended. The natural environment for CDS Views is SAP HANA Database. Therefore, even though you can (technically) use any database, you may run into performance issues if running complex SQL statements. That is because CDS views are primarily optimised and tested on SAP HANA Database.

The CDS Views features you can use also depend on your SAP NetWeaver version. They have been introduced in SAP NetWeaver ABAP 7.4 SP05, but the features are very limited in that release. The safest system version to start using CDS Views is SAP NetWeaver ABAP 7.5. Developing CDS Views on lower versions may cause issues in terms of what can be technically achieved due to lack of necessary features.

Development Environment

It is not possible to create CDS views in SAP GUI. The recommended tool for this task is Eclipse IDE with the ABAP Development Tools (ADT) plugin. This is a platform for modern ABAP related development. It is not limited to CDS views and can be used for developing other objects such as ABAP programs, classes, function modules etc.

ABAP CDS vs HANA CDS

CDS Views come in two flavours: ABAP CDS Views and HANA CDS Views. They share the same specification, but their implementations differ. ABAP CDS initial focus is on view building and integration into ABAP dictionary where HANA CDS focus is on building models from scratch. HANA CDS is located on the SAP HANA DB directly and are used to develop native SAP HANA applications (SAPA HANA XS), bypassing the ABAP application layer. If you are using a SAP ERP system you should focus on ABAP CDS Views technology which is located on the application server and fully integrated in the ABAP dictionary and the ABAP transport system as its purpose is to support the implementation of ABAP applications.

Did you find Radek’s blog post helpful? Follow us on LinkedIn to stay up to date with all new content from the Absoft team.

Did you find this article useful? View more detailed articles and use cases on:

Search by a topic below...

Read our latest articles...

Didn’t find what you are looking for? Send us your questions.

We are here to help.
Colleagues at work at Absoft SAP Consultancy