Let us now explore how the definition of entities can be enhanced with new elements using so-called aspects.
Watch the video to learn about CDS aspects.
In this lesson, we will learn about the extend directive. We will discuss the annotate directive later in another lesson.
The extend Directive
Using the extend directive you can add extension fields to existing definitions as shown in the following figure:

In the example, element someAdditionalField is added to the Authors domain entity. This also adds this field to the generated database table.
Note
Consumers always see the merged effective models, with the separation into aspects fully transparent to them.With the extend directive, metadata such as annotations can also be added to existing definitions or existing metadata can be overwritten.
Type properties can also be set via extend. For example, the length of an existing element of type String can be increased.
Named Aspects
You can use extend with predefined aspects to apply the same extensions to multiple targets, as shown in the following figure:

The example shows a named aspect ManagedObject that defines the two elements createdAt and createdBy. Both the Books and the Authors entity are extended by these fields via this named aspect.
Note
The syntaxaspect ManagedObject
has the same effect as the syntax define aspect ManagedObject
, i.e. the define
keyword is optional.A named extension can contain anything, such as fields, types or entities.
Includes as Shortcut Syntax
You can also use named aspects as includes in an inheritance-like syntax. This syntax allows you to extend a definition with several named aspects at the same time. In the following figure, the Authors entity is extended by the two named aspects ManagedObject and AnotherAspect.

Includes are syntactical sugar. The example shown is equivalent to using a sequence of extends as follows:
1234567entity Authors {}
extend Authors with ManagedObject;
extend Authors with AnotherAspect;
extend Authors with {
key ID : UUID;
...
}