This is a test message to test the length of the message box.
Login
ABAP CDS Basics
Created by Software-Heroes

CDS - Basics

493

Core data services are indispensable in an S/4 system, they form logical access to data and offer new ways of translating known tables.



Article update: Since release 7.57 (S/4 HANA 2022), DEFINE VIEW is marked as obsolete, you should use DEFINE VIEW ENTITY instead. These may differ from the examples in some places. You can find more information about the new views in this article.



Core Data Services, CDS for short, has been around since a 7.40 (SP05) release. Not particularly big yet, but already ready for the first use. CDS Views have evolved significantly in recent years and now form the basis for the ABAP RESTful Programming Model.

 

What are CDS Views?

Core Data Services represent a new type of view in the system and cannot be created using the classic workbench and can only be viewed using the SAP GUI in new releases. They are mainly used for the following things:

  • Abstract layer above the database
  • Entity and business object modeling
  • Normalization of data

 

The views are generated on the database and can then be viewed via the SE11, for example. The DDL source is then also available for this, the actual "code" to create the view.

 

Data model

If we take a look at a table, then this table can be read freely in the system and also changed. In the worst case, there is no central access (single point of access) to read and change the data, but each program has its own logic.

With CDS Views you now have the ability to use this view or subviews anywhere in your programs without worrying about fields in the table changing. If this is the case, only the lowest view (interface) has to be adjusted and the entire model continues to work without errors and does not notice the change.

As with using interfaces, the actual implementation doesn't matter as long as the interface remains stable. Hence the name of this layer.

 

Example

To do this, we create a simple CDS view for table T001 and give the fields corresponding English long names to make the meaning and background easier to understand. The view could now look like this:

@AbapCatalog.sqlViewName: 'ZBSICOMPCODE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Example for T001'
define view ZBS_I_CompanyCode
  as select from t001
{
  key bukrs as CompanyCode,
      butxt as CompanyCodeDescription,
      land1 as Country,
      waers as Currency,
      spras as Language,
      xprod as ProductiveFlag
}

 

We use so-called annotations in front of the view that start with @. These are not comments in the view, but controlling properties. The annotation "sqlViewName" defines the view on the database and the "label" field defines the description of the view. The name of the CDS view can now be longer than the table name and CamelCase works the same way here.

If you now look at the view in SE11, for example, you will see all the defined elements as we have created them in the definition.

 

From the SQL View we come to the definition and vice versa. Likewise, we see the translated field names. So how do we access this data? To do this, you can simply use a normal SELECT, which works in exactly the same way as with tables.

CLASS zcl_test_easy_cds DEFINITION PUBLIC FINAL CREATE PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_oo_adt_classrun.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.


CLASS zcl_test_easy_cds IMPLEMENTATION.
  METHOD if_oo_adt_classrun~main.
    SELECT *
      FROM ZBS_I_CompanyCode
      INTO TABLE @DATA(lt_all_companies).

    out->write( lt_all_companies ).

    SELECT CompanyCode, CompanyCodeDescription
      FROM ZBS_I_CompanyCode
      INTO TABLE @DATA(lt_company_names).

    out->write( lt_company_names ).
  ENDMETHOD.
ENDCLASS.

 

Search

How do you find Core Data Services in Eclipse? You can use the "Type" filter for this. To do this, you must specify the type DDLS and then you can search for the corresponding objects. Here we have an example search in which we want to search as CDS Views with Company and a certain pattern.

 

Code-Pushdown

A central component of the new view is the code pushdown, which is primarily about shifting computing power to the database. Operations like aggregation, JOIN, UNION or calculations should be performed by the database. The final result is then transferred to the ABAP stack and can be processed further. This means that a large part of the actions on the application server to read and merge additional data can be omitted.

In last week's article we presented the difference between R/3 and S/4 and that the database is very fast. We also want to use this function at this point.

 

Conclusion

Core data services will become increasingly important over the next few years and in a few years developers will only be talking about views instead of tables. In the next article we will take a closer look at the virtual data model.


Included topics:
CDSCore Data ServiceBasics
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP - CDS Extraktor

Category - ABAP

How does the CDS extractor work in ABAP and what challenges are there when developing with it? In this article we will look at a few details.

09/20/2024

ABAP Tools - Working with Eclipse (CDS Templates)

Category - ABAP

Did you select the wrong CDS template when creating the view? Here's a little tip to correct the view in ABAP afterwards.

07/02/2024

ABAP Tools - Work with Eclipse (CDS Analysis)

Category - ABAP

In the complex world of CDS views, it is important to have the right tool at hand to ensure an analysis of the structures and data sources.

08/25/2023

CDS - View Entity

Category - ABAP

In this article you will learn more about the new Core Data Service entities, what they bring and what makes them different from the old views.

07/29/2022

CDS - Learnings

Category - ABAP

In this article we summarize the learned content and show you the way for what you will need the CDS Views in the future.

06/10/2022