SAP ABAP TUTORIAL

Core Data Services (CDS) Views for Beginners: Your S/4HANA Foundation

Dive into Core Data Services (CDS) views for beginners. This guide covers their importance in S/4HANA, architecture, step-by-step creation, and practical applications for SAP MM and EWM professionals.

Anshuman Behuria
Anshuman BehuriaLead SAP Mentor · theTechMentor
Updated
Core Data Services (CDS) Views for Beginners: Your S/4HANA Foundation
ModuleSAP ABAP
Read time14 min
LevelBeginner
T-codes covered

SE11SE16NST05

In the world of SAP S/4HANA, data access and modeling have undergone a significant transformation. Gone are the days when classic ABAP Dictionary views or direct table reads were the primary ways to retrieve business data for reports and applications. Today, Core Data Services (CDS) views are at the heart of S/4HANA's simplified data model and provide a foundation for Fiori applications, analytics, and extensibility.

As an SAP MM or EWM professional in India, whether you're a fresher or an experienced consultant, understanding CDS views is no longer optional; it's essential. They empower you to access data efficiently, build robust custom solutions, and even troubleshoot standard processes by understanding their underlying data structures. This article is your comprehensive guide to Core Data Services (CDS) views for beginners, explaining not just what they are, but why they are crucial and how you can start working with them.

By the end of this guide, you will grasp the fundamental concepts of CDS views, their advantages over traditional approaches, and walk through creating a basic CDS view using ABAP Development Tools (ADT) in Eclipse. This knowledge will set a strong foundation for your S/4HANA journey.

⚡ Key takeaways
  • Core Data Services (CDS) views are SAP's modern, highly performant data modeling and access technology in S/4HANA, built on a DDL (Data Definition Language).
  • They enable 'code pushdown' by executing data logic directly on the HANA database, significantly improving performance over classic ABAP Dictionary views.
  • CDS views are categorized into layers like basic, composite, and consumption views within the Virtual Data Model (VDM), providing structured and reusable data access.
  • Annotations enrich CDS views with semantic meaning, crucial for Fiori apps, embedded analytics, and OData service generation.
  • Creating CDS views is done using ABAP Development Tools (ADT) in Eclipse, where you define their structure, relationships (like associations), and access control (DCL).
  • CDS views are fundamental for Fiori applications, ABAP programs, BI tools, and S/4HANA extensibility, making them an essential skill for MM/EWM consultants.
Process at a glance
  1. 1Setup ADT in EclipseInstall ABAP Development Tools (ADT) in your Eclipse environment.
  2. 2Create DDL Source (Eclipse)Right-click on your ABAP project and select 'New DDL Source' to define your CDS view.
  3. 3Define CDS View StructureWrite the DDL SQL using 'DEFINE VIEW' with associations, joins, and select elements.
  4. 4Add AnnotationsInclude relevant annotations to define view type, semantics, and Fiori enablement.
  5. 5Activate and TestActivate the CDS view and preview its data using the Data Preview tool in ADT.

01What are Core Data Services (CDS) Views?

Core Data Services (CDS) views represent SAP's modern approach to data modeling and access within the S/4HANA landscape. They are essentially virtual data models defined in the ABAP Dictionary, but with significantly enhanced capabilities compared to traditional views (like those created in SE11).

At their core, CDS views are based on a SQL-like Data Definition Language (DDL) and are executed directly within the database (HANA, in the case of S/4HANA). This concept is known as 'code pushdown,' where data-intensive operations are moved from the application server to the database layer, leveraging HANA's in-memory capabilities for superior performance. This shift is fundamental to S/4HANA's architecture and why CDS views are so integral.

02Key Advantages of Core Data Services (CDS) Views in S/4HANA

The adoption of CDS views brings numerous benefits, especially for MM and EWM consultants who need to extract, analyze, and extend business data. Understanding these advantages explains why SAP has made them central to S/4HANA:

03Types of CDS Views and Their Purpose

CDS views are not monolithic; they are categorized based on their purpose and how they integrate into the Virtual Data Model (VDM) architecture. The VDM is a layered approach that ensures reusability and structured data access. Here are the primary types:

1. Basic Interface Views (Private)

These views form the lowest layer of the VDM. They encapsulate the core business data, often performing simple joins or aggregations on database tables. They are typically not meant for direct consumption by end-user applications but rather serve as building blocks for higher-level views. They are marked with annotations like @AccessControl.authorizationCheck: #NOT_REQUIRED if they don't have direct access control, expecting higher layers to handle it.

2. Composite Interface Views

Building upon basic views, composite views combine data from multiple basic views or even other composite views. They add more complex business logic, aggregations, and associations, preparing the data for specific business scenarios. For example, a composite view could combine material master data with plant-specific stock data.

3. Consumption Views (Public)

These are the top-level views designed for direct consumption by Fiori apps, analytical queries, ABAP reports, or OData services. They expose business-ready data, often include extensive annotations for UI semantics, analytical use, and search functionalities. They are typically marked with @AccessControl.authorizationCheck: #REQUIRED to enforce proper authorization checks.

Other Specialized Types:

Understanding these layers helps in both consuming standard SAP CDS views and designing your own custom CDS views in a structured, performant manner.

04Architecture and Components of a CDS View

To truly grasp CDS views, it's essential to understand their underlying architecture and the components you'll encounter when working with them. The primary development environment for CDS views is Eclipse with the ABAP Development Tools (ADT) plugin, not the classic SAP GUI.

1. Data Definition Language (DDL)

CDS views are defined using a DDL, which is an extension of SQL. This language allows you to define the structure of your view, including:

The DDL source is stored in the ABAP Dictionary as a repository object, much like a classic table or view, but with the specific type 'DDL Source'.

2. Annotations

Annotations are meta-data tags prefixed with '@' that enrich the semantic meaning of CDS views and their elements. They provide crucial information for various consumers, including Fiori, analytics, and search. Examples include:

3. Data Control Language (DCL)

While DDL defines the data structure, DCL (Data Control Language) manages access to CDS views. Using DEFINE ROLE statements, you can define authorization rules based on user roles and specific field values. These security definitions are automatically enforced when a user tries to access data through the CDS view. For example, a DCL could ensure an MM consultant only sees purchase orders for their assigned purchasing organization.

4. Generated SQL View

When you activate a CDS DDL source, the system automatically generates a corresponding SQL view in the HANA database. This SQL view is what the database executes when the CDS view is called. You can find its technical name using the @AbapCatalog.sqlViewName annotation in your CDS DDL source.

05Creating Your First Core Data Services (CDS) View: A Step-by-Step Guide

Let's get practical and create a simple CDS view. For this, you will need access to an S/4HANA system and Eclipse with ABAP Development Tools (ADT) installed. This is the standard environment for modern ABAP development and CDS view creation.

Prerequisites:

Here’s how you define a basic CDS view to fetch Material Number and Material Type from MARA, and Material Description from MAKT, for all materials:

  1. Open Eclipse and Your ABAP Project: Navigate to your ABAP Project in the Project Explorer view.
  2. Create a New DDL Source:
    Right-click on your package (e.g., $TMP for local objects or a custom package) -> New -> Other ABAP Repository Object.
    In the filter, type DDL and select DDL Source under Core Data Services. Click Next.
  3. Define Properties:
    Enter a name for your DDL source, e.g., Z_I_MaterialBasic_## (replace ## with your initials).
    Enter a description, e.g., 'Basic Material View for Beginners'.
    Click Next, assign it to a transport request (or $TMP for local objects), and click Finish.
  4. Write the CDS View Code:
    The system will open a new editor with a basic template. Replace the content with the following code. This example uses an ASSOCIATION to link MARA and MAKT:

    @AbapCatalog.sqlViewName: 'ZMATERIALBASIC' "Technical name for the SQL view
    @AbapCatalog.compiler.compareFilter: true
    @AbapCatalog.preserveKey: true
    @AccessControl.authorizationCheck: #NOT_REQUIRED
    @EndUserText.label: 'Basic Material View for Beginners'
    DEFINE VIEW Z_I_MaterialBasic_##
      AS SELECT FROM mara AS Material
      association [1..1] to makt AS _MaterialText ON $projection.Material = _MaterialText.matnr
    {
        key Material.matnr   AS Material,
            Material.mtart   AS MaterialType,
            Material.meins   AS BaseUnit,
            _MaterialText.maktx AS MaterialDescription
    }
    WHERE
      _MaterialText.spras = 'E'; "Filter for English descriptions
    

    In this code:

    • @AbapCatalog.sqlViewName: This is crucial. It defines the technical name (ZMATERIALBASIC) that will be generated in the database. You can query this name in SE11 or SE16N later.
    • @EndUserText.label: Provides a user-friendly description.
    • DEFINE VIEW Z_I_MaterialBasic_##: Your CDS view name.
    • AS SELECT FROM mara AS Material: We are selecting data from the MARA table, aliased as Material.
    • association [1..1] to makt AS _MaterialText ON $projection.Material = _MaterialText.matnr: This defines an association to MAKT. [1..1] indicates a one-to-one relationship. The alias _MaterialText is used to refer to MAKT fields.
    • key Material.matnr AS Material: Defines matnr as the key field.
    • _MaterialText.maktx AS MaterialDescription: Retrieves the material description from the associated MAKT table.
    • WHERE _MaterialText.spras = 'E': Filters for English descriptions.
  5. Activate the CDS View:
    Save your code (Ctrl+S or Cmd+S). The system will automatically check for syntax errors. If clean, activate it (Ctrl+F3 or Cmd+F3).
  6. Preview the Data:
    Right-click on your active CDS view (Z_I_MaterialBasic_##) in the Project Explorer -> Open With -> Data Preview. You should see the material numbers, types, base units, and descriptions.

Congratulations! You have successfully created your first CDS view. This basic example demonstrates how to combine data from multiple tables using associations, leveraging code pushdown and providing a cleaner data access layer.

06Comparing Classic ABAP Views with CDS Views

While both classic ABAP Dictionary views (created via SE11) and CDS views provide structured access to data, their underlying technology, capabilities, and performance characteristics are vastly different. For a consultant working in S/4HANA, understanding these distinctions is vital.

FeatureClassic ABAP Dictionary Views (SE11)Core Data Services (CDS) Views (Eclipse ADT)
Creation EnvironmentSAP GUI (Transaction SE11)Eclipse with ABAP Development Tools (ADT)
Underlying TechnologyOpen SQL, executed on application server or DB interfaceDDL (Data Definition Language), executed directly on database (HANA)
PerformanceCan be slower for complex joins/aggregations as data moves to application server for processing.Optimized for performance via 'code pushdown' to the HANA database.
FunctionalityBasic joins (inner, outer, left outer), projections, selections. Limited aggregation.Rich DDL features: Associations, complex joins, aggregations, calculations, parameters, hierarchies.
AnnotationsNo native support for semantic annotations.Extensive support for annotations to provide semantic meaning (UI, Analytics, Search).
Fiori IntegrationNot directly integrated; requires OData service generation via Gateway.Native integration; directly consumed by Fiori apps and OData services.
ExtensibilityLimited extensibility; often requires copying and modifying standard views.Designed for extensibility; standard views can be extended with custom fields.
AuthorizationManaged via authorization objects at application level.Managed via DCL (Data Control Language) directly within the CDS view.
Use CaseLegacy reports, simple data extracts in ECC environments.Modern S/4HANA applications, Fiori, embedded analytics, new developments.

As you can see, CDS views are a clear advancement, tailored for the S/4HANA architecture and its in-memory database capabilities. For anyone dealing with S/4HANA data, the shift to CDS views is not just a recommendation but a necessity.

For more on how code pushdown revolutionized ABAP development, refer to our article on Mastering ABAP on HANA: Code Pushdown Techniques with Practical Examples.

07Consuming CDS Views in SAP Applications

Once a CDS view is created and activated, it's ready for consumption across various SAP landscapes. This is where the power of the unified data model truly shines, providing consistent data access regardless of the consuming application.

1. In ABAP Programs (Report/Classes)

You can directly select data from a CDS view within an ABAP program using Open SQL, just like you would with a database table or a classic view. The ABAP runtime automatically translates the CDS view into optimized SQL for the HANA database.

DATA: lt_materials TYPE TABLE OF Z_I_MaterialBasic_##,
      ls_material  TYPE Z_I_MaterialBasic_##.

SELECT * FROM Z_I_MaterialBasic_## INTO TABLE @lt_materials.

LOOP AT lt_materials INTO ls_material.
  WRITE: / ls_material-Material, ls_material-MaterialDescription.
ENDLOOP.

2. Fiori Applications

Fiori applications are the most prominent consumers of CDS views. The annotations within CDS views (e.g., @UI, @Analytics) directly drive the UI rendering, search capabilities, and analytical features of Fiori apps. When you explore a Fiori app, the data behind it is almost certainly sourced from one or more consumption CDS views.

3. OData Services

CDS views can be exposed as OData services, enabling external applications (e.g., mobile apps, web applications built with non-SAP technologies) to consume S/4HANA data. This simplifies integration and reduces the need for custom RFCs or SOAP services.

4. Embedded Analytics & BI Tools

For reporting and analysis, CDS views are invaluable. They form the basis for embedded analytics within S/4HANA (e.g., analytical Fiori apps, custom analytical queries) and can also be consumed by external Business Intelligence tools like SAP Analytics Cloud (SAC) or even third-party BI solutions. The rich semantic information provided by annotations makes integration seamless.

5. Extensibility in S/4HANA

When you need to add custom fields to standard SAP processes in MM or EWM, you often extend the underlying standard CDS views using 'Custom Fields and Logic' Fiori app. This ensures your custom data is available across all applications consuming that CDS view, from Fiori to reports, without modifying standard code.

Understanding how these various components leverage CDS views is key to developing and supporting S/4HANA solutions effectively.

08Common Mistakes and Troubleshooting for CDS Views

Even with a clear understanding, beginners often encounter specific issues when working with CDS views. Knowing these common pitfalls can save you significant troubleshooting time.

Always start with simple views, test them thoroughly, and gradually add complexity. Debugging CDS views often involves analyzing the generated SQL statements in HANA Studio or using ADT's built-in debugging capabilities for SQL queries.

09Interview Questions on Core Data Services (CDS) Views

For freshers and experienced consultants aiming for S/4HANA roles, interviewers frequently test your understanding of CDS views. Be prepared to answer questions that assess both theoretical knowledge and practical application.

  1. What are Core Data Services (CDS) views in SAP S/4HANA, and why are they important?
  2. How do CDS views differ from classic ABAP Dictionary views (created in SE11)? Mention at least three key differences.
  3. Explain the concept of 'code pushdown' and how CDS views support it.
  4. What is the Virtual Data Model (VDM) in S/4HANA, and what role do different types of CDS views (e.g., basic, consumption) play in it?
  5. Can you describe what annotations are in CDS views and provide a few examples of their usage?
  6. How do you create a CDS view in S/4HANA? What development environment is typically used?
  7. What is the purpose of associations in CDS views, and how do they differ from traditional joins?
  8. How are authorizations handled in CDS views? Explain the role of DCL.
  9. Where are CDS views consumed in the S/4HANA landscape (e.g., applications, tools)?
  10. You are working on a custom Fiori app for MM purchasing data. How would you typically access the data using CDS views?

Practicing these questions will strengthen your confidence in any SAP S/4HANA interview, especially for MM or EWM roles where data reporting and extension are common requirements.

If you're looking to master SAP MM, these concepts are crucial. Consider exploring our How to Master SAP MM in 3 Months guide for a structured learning path.

🎁
Free: SAP MM & EWM video course + interview kit

Get the 40+ lesson playlist, the most-asked interview questions and our 90-day roadmap on WhatsApp.

?Frequently asked questions

What are Core Data Services (CDS) in SAP?

Core Data Services (CDS) in SAP is an infrastructure that allows you to define and consume semantically rich data models in the underlying database. It's a key component of S/4HANA, enabling advanced capabilities like code pushdown, real-time analytics, and native Fiori integration.

What are Core Data Services views?

Core Data Services views are virtual data models defined using a SQL-based Data Definition Language (DDL). They encapsulate business logic and data access, providing a structured, performant, and extensible way to retrieve data from the S/4HANA database for various applications and reporting tools.

What is the primary benefit of CDS views in S/4HANA?

The primary benefit is performance optimization through 'code pushdown'. CDS views execute data-intensive operations directly on the SAP HANA database, leveraging its in-memory capabilities. This reduces data transfer and improves the speed of business processes and analytical queries significantly.

How do you create a CDS view?

CDS views are created using the ABAP Development Tools (ADT) in Eclipse. Developers write the view definition using a DDL (Data Definition Language) script, specifying tables, fields, joins, associations, and annotations. Once defined, the view is activated and can be consumed by applications.

Are CDS views only for ABAP developers?

While defining CDS views is an ABAP developer's task, their consumption is broad. Functional consultants in MM, EWM, SD, FICO often use or troubleshoot applications built on CDS views. Understanding their structure is crucial for custom report development, Fiori app extensions, and data analysis, making it relevant for a wider audience.

Learn SAP hands-on with theTechMentor

Live weekday & weekend batches or 24/7 recorded courses, with S/4HANA practice server access and interview preparation.