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

CDS - Basics

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

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)

CDS - Authority check

Category - ABAP

How and where are the permissions for a Core Data Service delimited? Check out this article for the details.

05/20/2022

CDS - Extension of Views

Category - ABAP

This article is about the extension of views to include customer-specific fields or to provide missing information.

05/13/2022

CDS - Performance

Category - ABAP

What is the access performance when using Core Data Services, can you make mistakes?

04/29/2022

CDS - Conversion routine

Category - ABAP

This article is about easy currency and quantity conversion directly in Core Data Services.

04/22/2022

CDS - Parameter

Category - ABAP

In this article we look at parameters in Core Data Services and how they can make your life easier or harder.

04/15/2022