Core Data Services | Create simple CDS VIEW

Core Data Services (CDS) views are an essential part of SAP's modern data modeling infrastructure. They allow you to define data models directly on the database layer, enabling faster data processing and efficient application development. In this blog, we will go over the important points of creating a CDS view, highlighting its significance and how it fits into the modern SAP landscape. This guide focuses on the concept, so you can add your own code and screenshots for the actual implementation.

Difference between Dictionary views and CDS views:

Dictionary Views

CDS views

Cannot perform calculations, aggregations, grouping

Can perform calculations, aggregations, grouping

Limited support for joins

Vast Support for Joins and Unions

Doesn’t support nested views

Support nested views(view on view)

DB view consumption takes place at application server level

Executed at Hana Database level

Can be developed on SE11 – ABAP Dictionary

Can be created in HANA Studio

 

What is a CDS View?  

CDS (Core Data Services) views are used to define and consume data models directly at the database level. Unlike traditional ABAP Dictionary views, CDS views go beyond data retrieval and allow complex data modeling with annotations, associations, and calculated fields, making them ideal for SAP S/4HANA applications. 

I’m creating CDS view in local object.

Navigation or steps:

Local object -> New -> Other ABAP Repository Object -> Core data services -> Data definition -> give name and description -> I’m creating local object so no need to select TR -> Click define view -> finish


Code:

@AbapCatalog.sqlViewName: 'ZCDSVIEW3'

@AbapCatalog.compiler.compareFilter: true

@AbapCatalog.preserveKey: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Sample cds view'

define view zcds_view3 as select from kna1

{

    kunnr as customerno,

    case land1

    when 'IN' then 'INDIA'

    when 'US' then 'UNITED STATES'

    when 'DE' then 'GERMANY'

    else 'OTHER' end as Country,

    name1 as CustomerName,

    ort01 as city

}

Key Points:

- Integration with HANA: CDS views take advantage of the power of SAP HANA by pushing the logic down to the database.

- Reusable: Once a CDS view is created, it can be reused in multiple applications and reports, reducing redundancy.

- VDM (Virtual Data Model): CDS views form the foundation of the Virtual Data Model (VDM), a key architecture element in SAP S/4HANA.

- Annotations: CDS views support annotations, which allow additional metadata to be embedded, making them highly flexible and customizable.

 Important Features of CDS Views

1. Efficient Data Modeling:

   CDS views allow for efficient data retrieval by pushing the logic to the database, which minimizes data transfer between the application and database layer.

2. Declarative Syntax:

   CDS views use a SQL-like declarative language, which makes them easy to write and understand.

3. Annotations:

   Annotations are key-value pairs that extend the functionality of the view. For example, annotations can define whether the view should be visible to end users or specify security restrictions.

4. Associations:

   CDS views support associations between different entities, which allow for more complex queries without the need for manual joins.

5. Enhancing Existing Models:

   Existing CDS views can be extended without modifying the original definition. This is useful for adding fields or annotations based on evolving business requirements.

6. Types of CDS Views:

   - Basic View: A simple view that pulls data from a table or multiple tables.

   - View with Associations: Allows you to define relationships between different entities.

   - Parameterized View: Enables passing of parameters to filter data.

   - Table Functions: Advanced CDS views that incorporate logic into the data model.

 CDS View Creation Process Overview

Here’s a quick overview of the steps involved in creating a CDS view:

1. Open SAP HANA Studio or ABAP Development Tools (ADT).

2. Create a new CDS View:

   - Navigate to Local Object → New → Other ABAP Repository Object.

   - Choose Core Data Services → Data Definition.

   - Provide a name and description.

   - Define the view by specifying the source tables and fields.

3. Activate the View: Once the view is activated, it generates a SQL view in the SAP database.

4. Test the CDS View: Execute the view and verify that the data is populated as expected.

Interview Questions

1. What is the main advantage of CDS views over traditional ABAP Dictionary views?

   CDS views allow complex data modeling, filtering, and aggregation directly at the database level. This reduces the load on the application server and speeds up data retrieval, especially with SAP HANA.

2. What is the role of annotations in CDS views?

   Annotations extend the functionality of CDS views by adding metadata. They can control behavior like security restrictions, data exposure, and how the view integrates with other components like SAP Fiori.

3. Explain the difference between a standard view and a CDS view.

   A standard view is created in the Data Dictionary (SE11) and has limited functionality. CDS views, on the other hand, are created directly in the ABAP layer, allowing for more complex queries, associations, and the use of annotations.

4. What are associations in CDS views, and how are they different from joins?

   Associations represent relationships between different entities in a CDS view. Unlike joins, associations are lazy-loaded and only processed when accessed, which improves performance.

5. What is a parameterized CDS view?

   A parameterized CDS view allows you to pass parameters when executing the view. This is useful when you want to filter the data dynamically based on input values.

6. Can you modify an existing CDS view without changing the original code?

   Yes, CDS views can be extended without modifying the original definition using the extend view keyword. This allows for additional fields or annotations to be added as needed.

7. What are the differences between a basic CDS view and a table function?

   A basic CDS view is primarily for reading data, while a table function is an advanced CDS view that includes logic for data processing.


Post a Comment

Previous Post Next Post