SAP HANA Development
SAP HANA CDS Views: Basics, Annotations, and Practical Troubleshooting
Learn how SAP HANA CDS views are structured, how annotations affect behavior, how they differ from calculation views, and how to troubleshoot them in a real development workflow.
SAP HANA CDS views
SAP HANA Core Data Services (CDS) provides a model-driven way to define data entities, relationships, metadata, and reusable semantics. A CDS view describes how data should be exposed or consumed, while the SAP HANA database executes the generated database objects behind that model.
The practical value of CDS is consistent data modeling. Instead of repeating joins, labels, associations, and semantic metadata in every consuming application, a development team can define them once and reuse the model across services, reports, and application logic.
CDS is a modeling technology rather than a replacement for every SQL or calculation-view use case. The right choice depends on the consumer, the deployment model, the required calculation logic, and the lifecycle tools used by the project.
CDS terminology in practice
The term CDS can refer to more than one development style. ABAP CDS views are defined in the ABAP development environment and are closely integrated with the ABAP data dictionary, authorization model, and application layer. SAP HANA CDS artifacts are database-oriented design-time objects used in HANA development scenarios.
CAP CDS is another modeling language used to define application entities and services. Its source models are compiled for the target runtime and should be evaluated according to the application framework that owns them. Keeping these variants separate prevents a deployment procedure for one type of CDS artifact from being applied to another.
How a CDS view is structured
A CDS definition normally identifies a data source, selects fields, and describes relationships or metadata. A simplified example looks like this:
namespace demo.sales;
@Schema: 'APP'
entity SalesOrder {
key OrderID : Integer;
CustomerID : String(20);
GrossAmount : Decimal(15,2);
CurrencyCode : String(3);
}
The exact syntax depends on the CDS technology and deployment environment. The important operational questions are consistent: which source objects are referenced, which fields are exposed, which fields are keys, and which annotations or associations influence the generated result.
A CDS model commonly contains:
- Entities or views that represent reusable data structures.
- Keys that identify rows or support associations.
- Associations that describe navigable relationships between entities.
- Annotations that provide metadata for persistence, access, semantics, or consumption.
- Namespaces that prevent naming collisions across packages and applications.
A key definition should reflect the real identity of the modeled data. An arbitrary key can cause duplicate rows, incorrect navigation, or unstable application behavior even when the underlying SQL appears valid.
When a model includes an association, verify both sides of the relationship. Check the source field, target entity, cardinality, and join condition. An association that looks correct in source code can still produce unexpected results when the cardinality does not match the data.
For broader context on how CDS fits into the development landscape, see SAP HANA development overview. Projects that deploy database artifacts through containers should also align the CDS model with SAP HANA HDI containers.
CDS view annotations
Annotations attach metadata to a CDS definition or one of its elements. They can influence persistence, access behavior, semantics, generated objects, or how a consuming framework presents the model.
Treat annotations as part of the model contract. A field label, currency relationship, unit relationship, or authorization-related annotation can change how downstream tools interpret the data without changing the visible SQL projection.
Useful annotation categories include:
- Modeling metadata: namespaces, labels, descriptions, and documentation.
- Persistence behavior: settings that determine whether a definition is persisted or generated.
- Semantic metadata: currency, unit, language, and text relationships.
- Consumption metadata: information used by services, analytical clients, or application frameworks.
- Authorization metadata: rules that connect the model to access checks where supported by the development stack.
Use annotations deliberately and document the reason for project-specific settings. An annotation copied from another model may refer to an object, framework, or deployment process that does not exist in the current system.
When a consuming application displays an amount without its currency, inspect the semantic relationship between the amount and currency fields first. When a text field does not appear in a user interface, inspect the text association and consumption metadata before changing the database projection.
CDS views versus calculation views
CDS views and calculation views can both expose modeled data, but they serve different development patterns. CDS is usually strongest when the model needs reusable entities, relationships, metadata, and application-oriented semantics. Calculation views are often a better fit for graphical modeling, complex analytical logic, unions, projections, restricted measures, and visual data-flow maintenance.
| Decision factor | CDS view | Calculation view |
|---|---|---|
| Primary focus | Reusable semantic data model | Analytical or transformation data flow |
| Definition style | Text-based model and annotations | Graphical or SQL-based modeling |
| Relationships | Associations and modeled navigation | Joins, unions, projections, and nodes |
| Metadata | Annotations are central | Properties and semantics are configured in the view |
| Typical consumer | Application, service, or reusable model | Analytical query, reporting, or complex transformation |
| Main troubleshooting area | Activation, annotations, dependencies | Node logic, mappings, filters, and runtime performance |
The choice should follow the consuming contract rather than personal preference. If the main requirement is an application-facing entity model with navigable relationships, CDS is often a natural starting point. If the requirement is a multi-stage analytical pipeline with visible transformations, a calculation view may make the logic easier to inspect.
Read SAP HANA calculation views when the design requires graphical modeling or analytical nodes. For SQL-based procedural logic that prepares or transforms data before consumption, SAP HANA SQLScript procedures may be a better fit.
A reliable CDS development workflow
A repeatable workflow reduces activation failures and makes dependency problems easier to isolate.
- Define the consumer contract. Record the intended fields, keys, filters, associations, semantics, and authorization expectations.
- Choose the CDS variant. Confirm whether the project uses ABAP CDS, SAP HANA CDS, or CAP CDS before creating artifacts.
- Map dependencies. Identify source tables, views, types, namespaces, and related entities.
- Build the smallest useful model. Start with the required projection and one relationship at a time.
- Activate or deploy early. A small deployable increment reveals naming, syntax, privilege, and dependency errors quickly.
- Validate data and metadata separately. Confirm row contents with SQL, then verify labels, units, associations, and consumer behavior.
- Test representative data. Include empty relationships, duplicate candidates, null values, large result sets, and authorization boundaries.
- Record the generated or deployed artifact names. This makes database-level troubleshooting much faster.
Use SAP HANA database explorer to inspect accessible database objects and execute focused validation statements. Use SAP HANA cockpit when the investigation also requires system-level monitoring or operational context. Keep model validation separate from application debugging so that a database activation problem does not get confused with a service serialization problem.
CDS troubleshooting checklist
Activation or deployment fails
Start with the first reported error, then inspect the dependency named in that message. Common causes include an unavailable source object, an incorrect namespace, an invalid field reference, a missing privilege, or an artifact deployed in the wrong order.
Confirm that the referenced object exists in the expected schema or container and that the deployment identity can access it. If several artifacts fail together, resolve the earliest dependency failure before changing the dependent definitions.
The view activates but returns incorrect rows
Check the join or association condition, key definition, filter placement, and expected cardinality. Duplicate rows commonly indicate that the relationship is broader than the modeled business key. Missing rows commonly indicate an inner-join behavior or a filter that removes unmatched data.
Validate the result with a small, known data set. Compare the CDS result with the underlying source records and test both matching and nonmatching relationship cases.
Metadata is missing in the consuming application
Inspect annotations and the consumer's metadata refresh behavior. A correct database projection does not guarantee that a service or user interface will display labels, units, text, or navigation links automatically.
Check that semantic fields are related correctly and that the consuming layer has refreshed its metadata after deployment. Keep the model's field names and annotations stable when they form part of an external service contract.
Performance is poor
Measure the generated database operation with realistic filters and data volumes. Review the number of projected fields, association paths, joins, calculated expressions, and unrestricted result sets. Avoid exposing broad entities when the consumer needs a narrow, filtered projection.
For complex analytical transformations, compare the CDS model with a calculation-view design and inspect the execution behavior of each approach. Performance tuning should preserve the intended semantics and authorization behavior rather than simply removing relationships or filters.
Operational checks before release
Before releasing a CDS model, verify the following:
- The model has a documented consumer and ownership boundary.
- Keys represent stable business or technical identity.
- Associations have tested cardinalities and conditions.
- Amounts, currencies, quantities, and units have consistent semantics.
- Authorization behavior has been tested with permitted and restricted users.
- Deployment order and dependencies are recorded.
- Empty, duplicate, null, and high-volume data cases have been tested.
- The consuming service or application has refreshed its metadata.
- SQL validation and application-level tests cover the same business examples.
A small regression dataset is especially useful. Keep examples that cover one valid relationship, one missing relationship, one duplicate candidate, and one restricted record. These cases expose most modeling errors earlier than a broad end-to-end test.
Key takeaways
- Use CDS as a reusable semantic model when entities, relationships, and metadata are central to the application.
- Choose the CDS variant that matches the project's development and deployment stack.
- Treat annotations as part of the contract because consumers rely on their semantics.
- Compare CDS with calculation views according to the required transformation and consumption pattern.
- Troubleshoot in order: dependencies, activation, data correctness, metadata, authorization, and performance.