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
- Model Categories, Products, and Orders using CDS.
- Expose services for frontend applications.
- Add business logic through handlers.
- 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.

WhatsApp us