Modeling Your First Domain with CDS Entities and Associations

Building robust CAP applications starts with understanding how to model your domain using CDS entities and associations. Domain modeling forms the foundation of every application, helping you define the structure of your data, the relationships between objects, and the behavior of your business logic. In this guide, we will walk you through modeling your first domain step by step, making it easy for beginners and corporate developers to follow.

If you are looking for structured learning while practicing CAP, consider enrolling in a hands-on SAP course. Additionally, learning SAP HANA will strengthen your understanding since CAP uses HANA for persistence in production.

What Is Domain Modeling in CAP?

Domain modeling is the process of representing real-world objects your application will manage. Examples include Products, Customers, Orders, or Employees. In CAP, this modeling is achieved through CDS, which allows you to define entities, relationships, constraints, and annotations in a clean, reusable way. Proper domain modeling ensures consistency, scalability, and maintainability across your application.

Understanding CDS Entities

A CDS entity represents a real-world object in your system. Each entity defines attributes, data types, keys, and constraints. Once defined, CAP can automatically generate database tables, OData endpoints, and metadata from these entities.

Example: Defining a Product entity

entity Products {
  key ID         : UUID;
      name       : String;
      price      : Decimal(10,2);
      stock      : Integer;
      createdAt  : Timestamp;
}

This single entity creates a database table with the defined columns, ready to be used in services.

Understanding Associations in CDS

Associations define relationships between entities, making it easy to model real-world connections like Customer → Orders or Product → Category. Associations support:

  • To-one relationships – e.g., a Product belongs to a Category.
  • To-many relationships – e.g., a Category contains multiple Products.

Example: Category → Product Relationship

Step 1: Define Category entity

entity Categories {
  key ID   : UUID;
      name : String;
}

Step 2: Define Product entity with association

entity Products {
  key ID         : UUID;
      name       : String;
      price      : Decimal(10,2);
      category   : Association to Categories;
}

You can query associated data like this:

SELECT from Products { ID, name, category.name };

Adding 1-to-Many Relationships

You can model ownership using Composition:

entity Categories {
  key ID   : UUID;
      name : String;
      products : Composition of many Products on products.category = $self;
}

Composition ensures that when a Category is deleted, all related Products are removed as well.

Adding Orders Entity

To complete a small e-commerce domain:

entity Orders {
  key ID        : UUID;
      quantity  : Integer;
      product   : Association to Products;
      orderedAt : Timestamp;
}

Now the domain includes Categories → Products → Orders, which is ready for service exposure and business logic.

Best Practices for Modeling Domains in CDS

  • Use UUIDs as primary keys for distributed consistency.
  • Name associations clearly to avoid confusion.
  • Use Composition when one entity owns another.
  • Organize CDS files for clarity (e.g., db/products.cds, db/orders.cds).
  • Apply annotations for UI behavior, validation, or service enhancements.

Real-World Example

  1. Model Categories, Products, and Orders using CDS.
  2. Expose services for frontend applications.
  3. Add business logic through handlers.
  4. Use annotations for automatic Fiori UI generation.

This approach reduces development time, ensures consistency, and aligns with SAP’s modern architecture.

Conclusion

Modeling your first domain using CDS entities and associations is the foundation for building scalable CAP applications. By clearly defining entities, relationships, and ownership, you create a system that is easy to extend, maintain, and deploy. For hands-on practice, strengthen your skills with an expert-led SAP course and learn how CAP integrates seamlessly with SAP HANA for production-grade applications.

Mastering CDS entities and associations is your first step toward becoming a confident CAP developer capable of building enterprise-ready applications.

you may be interested in this blog here:-

Don’t Fear the Update: Navigating the Challenges of how to implement sap note

Five Top Technology Investment Drivers for 2024

How many dollars worth of RSU does Salesforce typically offer an MTS (experienced hire) on joining?

Integration cloud system to HANA Cloud Platform using Cloud Connector

₹25,000.00

SAP SD S4 HANA

SAP SD (Sales and Distribution) is a module in the SAP ERP (Enterprise Resource Planning) system that handles all aspects of sales and distribution processes. S4 HANA is the latest version of SAP’s ERP suite, built on the SAP HANA in-memory database platform. It provides real-time data processing capabilities, improved…
₹25,000.00

SAP HR HCM

SAP Human Capital Management (SAP HCM)  is an important module in SAP. It is also known as SAP Human Resource Management System (SAP HRMS) or SAP Human Resource (HR). SAP HR software allows you to automate record-keeping processes. It is an ideal framework for the HR department to take advantage…
₹25,000.00

Salesforce Administrator Training

I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
₹25,000.00

Salesforce Developer Training

Salesforce Developer Training Overview Salesforce Developer training advances your skills and knowledge in building custom applications on the Salesforce platform using the programming capabilities of Apex code and the Visualforce UI framework. It covers all the fundamentals of application development through real-time projects and utilizes cases to help you clear…
₹25,000.00

SAP EWM

SAP EWM stands for Extended Warehouse Management. It is a best-of-breed WMS Warehouse Management System product offered by SAP. It was first released in 2007 as a part of SAP SCM meaning Supply Chain Management suite, but in subsequent releases, it was offered as a stand-alone product. The latest version…
₹25,000.00

Oracle PL-SQL Training Program

Oracle PL-SQL is actually the number one database. The demand in market is growing equally with the value of the database. It has become necessary for the Oracle PL-SQL certification to get the right job. eLearning Solutions is one of the renowned institutes for Oracle PL-SQL in Pune. We believe…
₹25,000.00

Pega Training Courses in Pune- Get Certified Now

Course details for Pega Training in Pune Elearning solution is the best PEGA training institute in Pune. PEGA is one of the Business Process Management tool (BPM), its development is based on Java and OOP concepts. The PAGA technology is mainly used to improve business purposes and cost reduction. PEGA…
₹27,000.00

SAP PP (Production Planning) Training Institute

SAP PP Training Institute in Pune SAP PP training (Production Planning) is one of the largest functional modules in SAP. This module mainly deals with the production process like capacity planning, Master production scheduling, Material requirement planning shop floor, etc. The PP module of SAP takes care of the Master…

X
WhatsApp WhatsApp us
Call Now Button