Usually, the entities of a data model are related to each other. Defining a data model includes defining these relationships.
Let's have a look at the data model of a company, which includes entities Employee and Department. The two entities are related because employees are assigned to departments.
But the two entities can share other relationships, too. For example, each department is lead by one of the employees.
Important characteristics of a relationship are its cardinalities or multiplicities. They tell you how many instances of one entity belong to an instance of the other entity.
There are different notation systems for cardinalities. The Unified Modeling Language (UML), for example, uses a maximum and minimum value, with * for an unrestricted maximum.
Let us have a look at our examples:
Every employee has to be assigned to exactly one department. Therefore the cardinality in this direction is 1..1. In the other direction, a department can have any number of employees assigned to it, even zero is allowed. Therefore, the cardinality is 0..*.
For the other relationship, let us consider that each department is led by exactly one employee, not more, not less. That means that we ignore special cases like vacant lead positions (Zero is an allowed value) or dual or multiple leadership (values greater than 1 are allowed). In the other direction, we can easily say that not every employee is a leader, which means the minimum is zero. We decide to set the maximum to 1, by which we express, that one employee can not lead two departments at the same time.
Note
In ABAP Dictionary and ABAP CDS, cardinality and multiplicity are used as synonyms. Strictly speaking, a cardinality is the actual number of instances, while the multiplicity specifies the range of allowed values.
ABAP CDS and ABAP Dictionary use different concepts to express relationships:
- Associations
ABAP CDS uses Associations to define relationships between CDS view entities. Usually, one relationship is reflected by two associations, pointing in opposite directions.
- Foreign Keys
ABAP Dictionary defines a dependency for table fields to establish a relationship to another database table. One such foreign key dependency corresponds to one relationship.
Let us explore the possibilities for defining relationships by having a closer look at foreign key dependencies in the ABAP dictionary.