Defining Relationships and Associations Flashcards

1
Q

What is cardinality, and why is it important in data models?

A

Cardinality, also known as multiplicity, describes how many instances of one entity relate to one instance of another entity. It is important because it defines the constraints and the nature of the relationships between entities, ensuring the integrity and accuracy of the data model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does UML notation express cardinality?

A

UML notation expresses cardinality with a range, using a minimum and maximum value. An asterisk (*) is used to indicate an unrestricted maximum. For example:

1..1 means exactly one instance.
0..* means zero or more instances.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the cardinalities for the relationship where every employee is assigned to a department?

A

In this relationship:

Every employee must be assigned to exactly one department: 1..1.
A department can have any number of employees, including zero: 0..*.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the cardinality for the relationship where each department is led by one employee.

A

For this relationship:

Each department is led by exactly one employee: 1..1.
Not every employee is a leader, and an employee can lead only one department: 0..1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the two ways relationships are expressed in ABAP Dictionary and ABAP CDS?

A

Relationships in ABAP Dictionary and ABAP CDS are expressed through:

  1. Associations in ABAP CDS, which define relationships between CDS view entities. Usually, this involves two associations pointing in opposite directions for a single relationship.
  2. Foreign Keys in ABAP Dictionary, which establish dependencies for table fields to relate to another database table. One foreign key dependency corresponds to one relationship.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the difference between cardinality and multiplicity.

A

Strictly speaking, cardinality refers to the actual number of instances of an entity, whereas multiplicity specifies the range of allowed values for these instances. In practice, especially in ABAP Dictionary and ABAP CDS, these terms are used synonymously to describe the constraints on entity relationships.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How are foreign key dependencies used in ABAP Dictionary to define relationships?

A

In ABAP Dictionary, foreign key dependencies are used to establish relationships by defining dependencies between table fields. This ensures that data in one table (the foreign key table) corresponds correctly to data in another table (the primary key table), thereby maintaining referential integrity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the primary purpose of foreign key dependencies in modern ABAP programming?

A

In modern ABAP programming, the primary purpose of foreign key dependencies is for documentation. In classical ABAP development, they also influenced the user interface by enabling implicit input checks and generating value helps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do foreign key definitions in the ABAP Dictionary affect database consistency checks?

A

Foreign key definitions in the ABAP Dictionary do not affect database consistency checks because they remain on the ABAP layer and are not passed on to the database. Therefore, they do not lead to implicit consistency checks on the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a foreign key dependency, and what are its components?

A

A foreign key dependency defines a relationship between two dictionary database tables: the foreign key table and the check table. It links each primary key field of the check table to a corresponding field in the foreign key table. The fields in the foreign key table that form the foreign key must match the primary key fields of the check table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are semantic attributes of foreign keys, and how are they used?

A

Semantic attributes of foreign keys provide additional information to describe the relationship and influence its usage. They include:

Short Description: An explanatory text for the relationship.

Foreign Key Field Type: Indicates whether the foreign key fields are key fields of the foreign key table (#KEY), not key fields (#NON_KEY), or if the foreign key table contains translatable text (#TEXT_KEY).

Value Check for Classical UI: Controls if classical user dialogues perform value checks based on the foreign key relationship.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How is cardinality specified for foreign key relationships in the ABAP Dictionary?

A

Cardinality is specified with [n, m] immediately after the keyword KEY:

Left side (n): Number of foreign key table records per check table record (values: 1, 0..1, 1.., 0..).

Right side (m): Number of check table records per foreign key table record (values: 1, 0..1).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In the employee and department example, what cardinality should be used if it is mandatory for an employee to be assigned to a department?

A

If it is mandatory for an employee to be assigned to a department, the cardinality should have m = 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the left-hand side of the cardinality represent, and what are the possible values?

A

The left-hand side (n) represents the number of dependent records (foreign key table records) per check table record:

n = 1: Exactly one dependent record.
n = 0..1: At most one dependent record.
n = 1..: At least one dependent record.
n = 0..
: Any number of dependent records, including none.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Given the requirement that each department can have multiple employees, but an employee can belong to exactly one department, what is the appropriate cardinality?

A

The appropriate cardinality for this requirement is (0..*, 1), indicating that:

A department can have any number of employees (0..*).
Each employee must belong to exactly one department (1).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the main difference between foreign key dependencies and associations in CDS views?

A

The main difference is that foreign key dependencies link a foreign key table to a check table, while associations in CDS views are more flexible and can link any association source to any association target. Associations can also be bi-directional, unlike foreign key dependencies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How many associations can a single CDS view definition contain?

A

A single CDS view definition can contain any number of associations. For instance, some views in the SAP S/4HANA data model contain over one hundred associations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the components of an association definition in a CDS view?

A

An association definition in a CDS view consists of the following parts:

  1. Association Target: Defined using the association to keyword followed by the name of the association target, which should be a CDS entity.
  2. Association Name: An identifier for the association defined using the AS addition. It’s recommended to start with an underscore (_).
  3. Association Condition: Defined using the ON keyword, usually comparing view elements of the association source to those of the association target.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Why is it recommended to define an association name?

A

Defining an association name is recommended because:

It improves code readability.
It allows for having more than one association to the same target.
It avoids confusion by providing a clear identifier for each association.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you format the association condition in a CDS view?

A

The association condition is formatted as follows:

It starts with the ON keyword.
The view elements of the association source are on the left, prefixed with $projection..
The view elements of the association target are on the right, prefixed with the association name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Can database tables be used as targets in CDS view associations?

A

While it is possible to use database tables as targets in CDS view associations, it is not recommended. It is better to use CDS entities as targets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

In the example provided, what are the names of the CDS views for the EMPLOYEE and DEPARTMENT tables?

A

In the example, the CDS views for the EMPLOYEE and DEPARTMENT tables are named R_Employee and R_Department, respectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Provide an example of defining an association in the CDS view R_Employee linking it to R_Department.

A

define view R_Employee as select from Employee
association to R_Department as _Department
on $projection.DEPARTMENT_ID = _Department.DEPARTMENT_ID
{
key EMPLOYEE_ID,
FIRST_NAME,
LAST_NAME,
DEPARTMENT_ID,
_Department
}

In this example:

R_Department is the association target.
_Department is the association name.
The association condition links EMPLOYEE.DEPARTMENT_ID to DEPARTMENT.DEPARTMENT_ID.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is a practical tip when defining an association in a CDS view?

A

A practical tip is to use code completion (Ctrl + Space) to insert keywords, the name of the association target, and view elements. This helps ensure accuracy and saves time.

25
Q

What is the cardinality of an association in ABAP CDS and how is it specified?

A

The cardinality of an association specifies the number of possible data sets in the association target for one data set in the association source. It is specified in a pair of square brackets immediately after the keyword association, either as [min..max] or just [max]. If min is omitted, it defaults to 0.

26
Q

What are the allowed values for min and max in the cardinality of an association?

A

Allowed values for min are 0 and all positive integers, with the most common values being 0 and 1.

Allowed values for max are all positive integers and the asterisk sign (*) for an unrestricted maximum, with the most common values being 1 and *.

27
Q

What is the default cardinality if none is specified?

A

The default cardinality is [0..1] if none is specified.

28
Q

What does the syntax check for cardinality in ABAP CDS do?

A

The syntax check performs a plausibility check for the maximum value of a cardinality by comparing the ON-condition to the key of the association target. If the ON-condition fully qualifies the primary key, a cardinality of [0..1] or [1..1] is expected.

29
Q

What might cause a syntax warning when defining a cardinality of [1..1] for an association?

A

A syntax warning may occur if the key field of the association target is not fully qualified in the ON-condition. For example, defining a cardinality of [1..1] for the association _Employee might lead to a warning if the key field EmployeeID of R_Employee is not fully qualified in the ON-condition.

30
Q

What should you do if a cardinality is correct but does not match the ON-condition, resulting in a syntax warning?

A

In such cases, you can ignore the warning or suppress it using a pseudo-comment, as complex data models might have correct cardinalities that do not match the ON-condition exactly.

31
Q

How do you expose an association in a CDS view?

A

To expose an association, add the association name to the element list of the CDS view. This makes the association visible to the consumer of the view.

32
Q

What prerequisite must be fulfilled when exposing an association?

A

When exposing an association, all elements of the association source used in the ON-condition must be part of the field list. This is automatically fulfilled if you use the $projection prefix in the ON-condition.

33
Q

How can you evaluate exposed associations in the Data Preview tool?

A

Open the CDS View in Data Preview.

Choose one of the displayed rows, then click on the arrow next to the view name in the header toolbar.

Alternatively, right-click the entry and choose “Follow Association”.

Choose an association from the list of available associations to evaluate it.

34
Q

Provide an example of defining an association with cardinality in a CDS view.

A

define view R_Employee as select from Employee
association [1..*] to R_Department as _Department
on $projection.DEPARTMENT_ID = _Department.DEPARTMENT_ID
{
key EMPLOYEE_ID,
FIRST_NAME,
LAST_NAME,
DEPARTMENT_ID,
_Department
}

In this example:

The association target is R_Department.
The association name is _Department.
The cardinality [1..*] indicates that each employee must belong to at least one department, and each department can have multiple employees.

35
Q

What are the two possibilities when a CDS view entity reads from an entity with exposed associations?

A

Propagating the association: By adding the association name to the element list, making the association visible to the consumers of the view.

Using the association: By using a path expression (adding a period sign and an element name after the association name) to read data from the association target.

36
Q

How does a path expression in a CDS view work at the database level?

A

At the database level, a path expression is translated into a join between the association source and the association target. The ON-condition for this join is derived from the ON-condition of the association.

37
Q

What is the role of a LEFT OUTER MANY TO ONE JOIN in SAP HANA?

A

In SAP HANA, a LEFT OUTER MANY TO ONE JOIN is used when the association cardinality indicates that many source records relate to one target record. There is also a LEFT OUTER MANY TO MANY JOIN used for associations with cardinalities that allow multiple target records.

38
Q

What is meant by “Join on Demand” in the context of CDS associations?

A

“Join on Demand” means that the join at the database level is only created when the association is actually used in a path expression. Merely defining, exposing, or propagating an association does not create the join.

39
Q

How can longer path expressions be constructed in CDS views?

A

Longer path expressions can be constructed by chaining several associations. For example:
_Department._Head.LastName

This reads the last name of the head of the department to which an employee is assigned, chaining through the _Department and _Head associations.

40
Q

What is an ad-hoc usage of associations in CDS views?

A

Ad-hoc usage of associations occurs when a CDS view directly uses an association in a path expression instead of, or in addition to, exposing it. This means the join is built immediately in the SQL view for that CDS view entity.

41
Q

What happens if you define and expose an association but do not use it in a path expression?

A

If you define and expose an association but do not use it in a path expression, no join is created at the database level. The SQL view will only read from the initial entity without incorporating the association.

42
Q

Explain the following example of a path expression used in a CDS view.

define view C_Employee as select from R_Employee
association to R_Department as _Department
on $projection.DEPARTMENT_ID = _Department.DEPARTMENT_ID
{
key EMPLOYEE_ID,
FIRST_NAME,
LAST_NAME,
DEPARTMENT_ID,
_Department.DepmentDesignation as DepartmentDesignation
}

A

In this example:

The association _Department is defined and used in a path expression.

The path expression _Department.DepmentDesignation reads the DepmentDesignation field from the R_Department entity and adds it to the element list of C_Employee.

43
Q

How does the cardinality of an association influence path expressions in CDS views?

A

The cardinality influences the syntax check. Using “to many” (“to”, not “too”!) associations (with max > 1) in the WHERE-clause results in a syntax error. In the element list, it is allowed but may result in warnings indicating the potential for altering the number of result sets.

44
Q

What does the warning about modifying the number of result sets mean in the context of path expressions?

A

It means that using a “to many” association in a path expression can increase the number of resulting data sets. For example, if a view initially returns one data set per department, adding a path expression with a “to many” association to employees could result in multiple data sets per department, one for each employee.

45
Q

How can you correctly use a “to many” association in a path expression?

A

Aggregation: Use the path expression inside an aggregation with a GROUP-BY clause to ensure the number of data sets remains the same.

Filters: Apply a filter condition to restrict the results appropriately.

46
Q

What is the purpose of adding filters to path expressions in CDS views?

A

Filters in path expressions are used to restrict the data sets of the association target. This helps in narrowing down the results to specific conditions, similar to a WHERE clause in SQL.

47
Q

How are filters added to path expressions?

A

Filters are added by placing the filter condition inside square brackets [ ] immediately after the association name. The filter can include relational and boolean operators (AND, OR, NOT), and the left-hand side must be a field from the association target.

48
Q

How is the filter condition applied at the database level?

A

The filter condition is added to the ON-condition of the generated join at the database level.

49
Q

What happens if a filter condition transforms a “to many” association into a “to one” association?

A

If a filter condition ensures that only one entry remains in a “to many” association, it effectively turns it into a “to one” association. This should be documented by adding 1: in front of the filter condition to indicate the changed cardinality.

50
Q

Provide an example where a “to many” association is transformed into a “to one” association by a filter condition.

A
51
Q

Will the syntax check still issue warnings and errors if a filter turns a “to many” association into a “to one” association?

A

Yes, the syntax check will still issue warnings and errors because it cannot automatically determine that the filter changes the cardinality. Adding 1: before the filter condition helps document this change and avoid warnings.

52
Q

What is a key difference between path expressions in CDS and ABAP SQL regarding association prefixes?

A

In ABAP SQL path expressions, associations have to be escaped with a backslash (), while in CDS path expressions, no special prefix is needed.

53
Q

How are element selectors used differently in CDS and ABAP SQL path expressions?

A

In CDS path expressions, a period sign (.) is used as the separator between the association name and the element name. In ABAP SQL, a hyphen (-) is used instead.

54
Q

How would you write a path expression in ABAP SQL to read the Name element from an association _Airline exposed in the CDS view entity /DMO/I_Connection_R?

A
55
Q

How are chained associations handled differently in ABAP SQL compared to CDS?

A

In ABAP SQL, when a path expression contains a sequence of associations, there is no dedicated separator between them, but each association name needs a backslash () as a prefix. In CDS, associations are separated by a period sign (.).

56
Q

How do you add filter conditions in ABAP SQL path expressions?

A

Filter conditions in ABAP SQL path expressions are added in square brackets [ ], similar to CDS.

57
Q

Which of the following is the default cardinality of an association if no cardinality is specified?

A
none

B
[0..*]

C
[0..1]

D
[1..1]

A

C
[0..1]

58
Q

You define a foreign key dependency in the ABAP dictionary. What effect does it have?

A
The relationship is documented on ABAP dictionary level.

B
Enforced data consistency on database level.

C
Generated input checks in classical user dialogues.

D
Generated input checks in a SAP Fiori application.

A

A
The relationship is documented on ABAP dictionary level.

C
Generated input checks in classical user dialogues.

That is correct. In classical ABAP programming, foreign key dependencies were used to generate implicit input checks. I modern ABAP programming they are used to document the relations on ABAP dictionary level.

59
Q

You define a CDS view entity with an association. When is the association translated into a join on database level?

A
As soon as you define the association.

B
When you use the association in a path expression.

C
When you add the association to the element list.

A

B
When you use the association in a path expression.

That is right. Only when you use the association in a path expression, it is translated into a join.