Appearance
Lesson 5 Practice — Booking Associations
In Lesson 4 practice, you solved the booking problem with explicit joins. The guided Lesson 5 material now provides the association concepts you will apply here.
Now solve the same kind of problem with reusable CDS relationships.
Your architecture will be:
text
/DMO/BOOKING
↓
ZI_BOOKING_ASSOC_###
├── _Customer ───► /DMO/I_CUSTOMER
├── _Carrier ────► /DMO/I_CARRIER
└── _Connection ─► /DMO/I_CONNECTION
↓
Booking Reader
↓
RunnerThe complete solution is intentionally not included here.
Objects to create
text
ZI_BOOKING_ASSOC_###
ZCL_BOOKING_ASSOC_READER_###
ZCL_CDS_L05_PRACTICE_###Optional challenge:
text
ZI_CARRIER_CONNECTIONS_###Replace ### with your student/group suffix.
Part 1 — Inspect the target CDS entities
Open each target using:
text
Ctrl + Shift + AInspect:
text
/DMO/I_CUSTOMER
/DMO/I_CARRIER
/DMO/I_CONNECTIONRecord the keys.
/DMO/I_CUSTOMER
text
Key:/DMO/I_CARRIER
text
Key:/DMO/I_CONNECTION
text
Key field 1:
Key field 2:Do not continue until you know the complete key of /DMO/I_CONNECTION.
Part 2 — Inspect /DMO/BOOKING
Open:
text
/DMO/BOOKINGIdentify:
text
travel_id
booking_id
booking_date
customer_id
carrier_id
connection_id
flight_date
flight_price
currency_codeConfirm the booking key:
text
travel_id + booking_idPart 3 — Plan the relationships
Complete:
text
Booking.customer_id
→ ______________________________
Booking.carrier_id
→ ______________________________
Booking.carrier_id + Booking.connection_id
→ ______________________________For each relationship, decide:
text
to-one or to-many?Write a one-sentence reason for each answer.
Part 4 — Create ZI_BOOKING_ASSOC_###
Create a Data Definition.
Use:
text
Name: ZI_BOOKING_ASSOC_###
Description: Lesson 5 - Booking AssociationsChoose a CDS View Entity template.
Primary source:
text
/DMO/BOOKINGAlias:
text
BookingPart 5 — Build the base model first
Before adding associations, expose:
text
TravelId
BookingId
BookingDate
CustomerId
CarrierId
ConnectionId
FlightDate
FlightPrice
CurrencyCodeMark only the booking identifier fields as CDS keys.
Run:
text
Ctrl + F2Activate:
text
Ctrl + F3Preview:
text
F8Part 6 — Define _Customer
Create an association to:
text
/DMO/I_CUSTOMERUse the name:
text
_CustomerChoose the cardinality based on:
text
one booking → how many customer targets?Use:
text
$projection.CustomerIdin the ON condition.
Hint
The target key is named:
text
CustomerIDPart 7 — Add Customer path fields
Through _Customer, expose:
text
CustomerFirstName
CustomerLastNameThe target fields are:
text
FirstName
LastNameUse CDS path expressions.
Part 8 — Expose _Customer
Add:
abap
_Customeritself to the element list.
Activate.
Open Data Preview.
Use:
text
Follow Association
→ _CustomerConfirm that ADT navigates to the related customer data.
Part 9 — Define _Carrier
Create an association to:
text
/DMO/I_CARRIERUse:
text
_CarrierUse the current projection's:
text
CarrierIdin the relationship condition.
Expose the target's:
text
Nameas:
text
CarrierNameThen expose:
text
_Carrieritself.
Part 10 — Follow _Carrier
Activate.
Open Data Preview.
Choose:
text
Follow Association
→ _CarrierVerify target fields such as:
text
AirlineID
Name
CurrencyCodeagainst the booking's CarrierId.
Part 11 — Define _Connection
This is the key reasoning task.
Target:
text
/DMO/I_CONNECTIONAssociation name:
text
_ConnectionBefore writing the ON condition, answer:
What is the complete target key?
The booking provides:
text
CarrierId
ConnectionIdYour association must use the complete relationship.
WARNING
Do not associate only on ConnectionId.
/DMO/I_CONNECTION has a composite key.
Hint
Your condition needs two comparisons joined with:
abap
andPart 12 — Add Connection path fields
Through _Connection, expose:
text
DepartureAirportId
DestinationAirportId
DepartureTime
ArrivalTimeThe target provides:
text
DepartureAirport
DestinationAirport
DepartureTime
ArrivalTimePart 13 — Expose _Connection
Add:
abap
_Connectionto the element list.
Activate.
Open Data Preview and use:
text
Follow Association
→ _ConnectionCheck that the target:
text
AirlineID
ConnectionIDmatches:
text
CarrierId
ConnectionIdfrom the booking.
Part 14 — Final scalar model requirements
Your CDS entity should expose:
text
TravelId
BookingId
BookingDate
CustomerId
CustomerFirstName
CustomerLastName
CarrierId
CarrierName
ConnectionId
DepartureAirportId
DestinationAirportId
DepartureTime
ArrivalTime
FlightDate
FlightPrice
CurrencyCodeIt should also expose:
text
_Customer
_Carrier
_ConnectionPart 15 — Compare the Lesson 4 and Lesson 5 designs
Write:
text
Lesson 4:
Booking __________ Customer
Lesson 5:
Booking __________ CustomerUse:
text
JOIN
ASSOCIATIONThen answer:
What capability does the exposed association provide that a copied
CustomerNamescalar field alone does not?
Part 16 — SQL Console
Query:
text
ZI_BOOKING_ASSOC_###Return at least:
text
TravelId
BookingId
CustomerFirstName
CustomerLastName
CarrierName
DepartureAirportId
DestinationAirportId
FlightDateOrder by:
text
TravelId
BookingIdThe SQL query should not contain joins to Customer, Carrier, or Connection.
Part 17 — Filter by Carrier
Choose a CarrierId present in your booking data.
Filter in SQL Console.
Confirm that:
text
CarrierNameis available even though it came through an association path.
Part 18 — Create the Reader
Create:
text
ZCL_BOOKING_ASSOC_READER_###Do not implement:
text
IF_OO_ADT_CLASSRUNDefine:
text
TT_BOOKINGSas a standard table of:
text
ZI_BOOKING_ASSOC_###with:
text
WITH EMPTY KEYPart 19 — Implement GET_ALL
Create:
text
GET_ALLRequirements:
- return
TT_BOOKINGS; - select from
ZI_BOOKING_ASSOC_###; - use
FIELDS *; - order by
TravelId,BookingId; - contain no explicit joins;
- contain no association definitions.
Part 20 — Implement GET_BY_CARRIER
Create:
text
GET_BY_CARRIERImport:
text
carrier_idRequirements:
- select from
ZI_BOOKING_ASSOC_###; - filter on
CarrierId; - use an ABAP SQL host variable;
- return
TT_BOOKINGS; - order by the booking key.
Part 21 — Create the Runner
Create:
text
ZCL_CDS_L05_PRACTICE_###Implement:
text
IF_OO_ADT_CLASSRUNIn main:
- instantiate the Reader;
- call
GET_ALL; - loop through the result;
- display a useful line containing:
text
TravelId/BookingId
FirstName LastName
CarrierName
DepartureAirportId → DestinationAirportIdDesign the exact format yourself.
Part 22 — Test GET_BY_CARRIER
Use a carrier ID present in your tenant.
Call:
text
GET_BY_CARRIERDisplay the result.
Confirm the architecture:
text
Runner
↓
Reader
↓
ZI_BOOKING_ASSOC_###
↓
associationsThe Reader and Runner should not recreate the relationships.
Part 23 — Cardinality table
Complete:
| Association | Cardinality | Why? |
|---|---|---|
_Customer | ||
_Carrier | ||
_Connection |
Your reason must answer:
How many target records are expected for one booking?
Part 24 — Explain a path expression
For:
abap
_Carrier.Nameanswer:
What is _Carrier?
What is Name?
What scalar element did you create from this path?
What database join behavior is generated by default for a CDS path target field?
Part 25 — Scalar field vs exposed association
Explain the difference between:
abap
_Carrier.Name as CarrierNameand:
abap
_CarrierUse:
text
scalar value
relationship
navigationin your explanation.
Part 26 — Direction
Your model contains:
text
Booking → CustomerDoes that automatically add:
text
Customer → BookingExplain why or why not.
Part 27 — Optional challenge: Carrier → Connections
Create:
text
ZI_CARRIER_CONNECTIONS_###Primary source:
text
/DMO/I_CARRIERAlias:
text
CarrierExpose:
text
CarrierId
CarrierNameCreate an association:
text
_Connectionsto:
text
/DMO/I_CONNECTIONDecide cardinality based on:
text
one carrier → how many connections?Expose the association itself.
Do not flatten every connection field into the carrier row.
Part 28 — Follow the to-many association
Activate:
text
ZI_CARRIER_CONNECTIONS_###Open Data Preview.
Use:
text
Follow Association
→ _ConnectionsInspect the related connection records.
Answer:
Why is _Connections not [1..1]?
Why can one source carrier lead to several target rows?
Part 29 — Connect to Lesson 4 row multiplication
Answer:
If you flatten a target field through a to-many association, why can one source row become several result rows?
Use the Lesson 4 concept:
text
row multiplicationPart 30 — Reasoning questions
Answer in your own words.
1. What does a CDS association represent?
2. How is an association different from an explicit join?
3. Why are associations directional?
4. What does cardinality describe?
5. Why is _Connection a to-one relationship from Booking?
6. Why must _Connection use both CarrierId and ConnectionId?
7. What does $projection.CustomerId mean?
8. What does _Customer.LastName mean?
9. What happens when a path target field is used in a CDS element list?
10. What does exposing _Customer add to the public CDS model?
11. What ADT feature lets you inspect an exposed association?
12. Why can Carrier → Connections be [0..*] while Booking → Carrier is [1..1]?
13. Why is cardinality more than documentation?
14. How do associations prepare a CDS model for later RAP/service navigation?
Submission checklist
Useful ADT shortcuts
| Action | Shortcut |
|---|---|
| Open ABAP Development Object | Ctrl + Shift + A |
| Code completion | Ctrl + Space |
| Navigate | F3 / Ctrl + click where supported |
| Syntax check | Ctrl + F2 |
| Activate current object | Ctrl + F3 |
| Activate inactive objects | Ctrl + Shift + F3 |
| CDS Data Preview | F8 |
| Run console class | F9 |
| Format source | Shift + F1 |