Building Views on Views


After completing this lesson, you will be able to:

  • Define a CDS view that reads from another view
  • Control the propagation of element annotations

View on View - Motivation

When you define a CDS view entity, you can not only read from database tables, you can also use other CDS views as data source. Why would you build views on top of views?

  • The first reason is similar to the reasoning when structuring source code in classes and methods:

    • Reuse existing functionality
    • Avoid redundancies
    • Support error analysis and maintenance
  • The second argument is more technical. There are certain limitations when it comes to the nesting of SQL expressions and SQL functions within the same CDS view. Nested views are a common technique to overcome such restrictions.
  • Probably the most important reason for nested views is the layering of your data model. In the ABAP RESTful Programming Model, for example, it is recommended that you define consumption views on top of data model views. While the data model views contain the general data model logic, the consumption views add consumption specific logic and metadata.

Propagated Annotations

If a CDS view entity reads from another view entity it can inherit metadata from the source view. This is called annotation propagation.

In this example, CDS view entity C_Employee uses CDS view entity R_Employee as data source. By default, the element annotations of R_Employee get propagated into C_Employee. As a consequence, annotation @Semantics.amount.currencyCode is not required in C_Employee, again.

Propagation is restricted to element annotations. Entity and view annotations never get propagated.

Entity annotation @Metadata.ignorePropagatedAnnotations allows you to control the propagation of element annotations. If it is missing from the reading CDS view entity, or is set to value false, element annotations are inherited. With @Metadata.ignorePropagatedAnnotations: true the propagation of element annotations is disabled.

If in our example, CDS view entity C_Employee is annotated with @Metadata.ignorePropagatedAnnotations: true, the @Semantics.amount.currencyCode annotation for element AnnualSalary is not propagated. The syntax check displays an error because the mandatory annotation is missing for the amount field.

How to Define a View on Top of a View

Play the video to see how to define a view on top of a view.

Log in to track your progress & complete quizzes