Appearance
Lesson 3 Practice — Connection Modeling
In Lesson 3, you created:
text
/DMO/FLIGHT
↓
ZI_FLIGHT_###
↓
calculated elements
↓
ZI_AVAILABLE_FLIGHT_###
↓
filtered modelIn this practice, apply the same ideas to:
text
/DMO/CONNECTIONYour target architecture is:
text
/DMO/CONNECTION
↓
ZI_CONNECTION_###
├─ RouteCode
└─ DeparturePeriod
↓
ZI_MORNING_CONNECTION_###
↓
Connection Reader
↓
RunnerThis assignment does not contain the complete source solution.
Objects to create
Create:
text
ZI_CONNECTION_###
ZI_MORNING_CONNECTION_###
ZCL_CONNECTION_READER_###
ZCL_CDS_L03_PRACTICE_###Replace ### with your student/group suffix.
Part 1 — Explore /DMO/CONNECTION
Open:
text
/DMO/CONNECTIONwith:
text
Ctrl + Shift + AIdentify:
text
carrier_id
connection_id
airport_from_id
airport_to_id
departure_time
arrival_time
distance
distance_unitConfirm that the key is:
text
carrier_id + connection_idOpen Data Preview.
Record at least three connections with different departure times.
Part 2 — Plan the model
Your base CDS model should expose:
text
CarrierId
ConnectionId
AirportFromId
AirportToId
DepartureTime
ArrivalTime
Distance
DistanceUnit
RouteCode
DeparturePeriodTwo elements must be derived:
text
RouteCode
DeparturePeriodPart 3 — Define RouteCode
Use the CDS built-in function:
text
CONCAT_WITH_SPACECombine:
text
AirportFromId
AirportToIdwith one space between them.
Example result:
text
FRA JFKHint
The function shape is:
abap
concat_with_space(
<first value>,
<second value>,
1
)Answer:
Why is
RouteCodea calculated element rather than a persisted field?
Part 4 — Define DeparturePeriod
Classify each connection using its departure time.
Rules:
text
before 12:00 → Morning
before 18:00 → Afternoon
otherwise → EveningUse a searched CASE expression.
Use typed time literals:
abap
abap.tims'120000'
abap.tims'180000'Use typed character literals for the result values.
Hint
The structure is:
abap
case
when ...
then ...
when ...
then ...
else ...
end as DeparturePeriodPart 5 — Create ZI_CONNECTION_###
Create a Data Definition.
Use:
text
Name: ZI_CONNECTION_###
Description: Lesson 3 - Connection CDSSource:
text
/DMO/CONNECTIONSource alias:
text
ConnectionRequirements:
CarrierIdis a key;ConnectionIdis a key;- expose all fields listed in Part 2;
- calculate
RouteCode; - calculate
DeparturePeriod; - use
@AccessControl.authorizationCheck: #NOT_REQUIRED; - add a useful end-user label.
Use:
text
Ctrl + Spacefor code completion.
Part 6 — Check, activate, and preview
Run:
text
Ctrl + F2Fix all syntax errors.
Activate:
text
Ctrl + F3Preview:
text
F8Verify RouteCode and DeparturePeriod for several rows.
Check manually that a departure before 12:00 is classified as Morning.
Part 7 — SQL Console
Query ZI_CONNECTION_### in SQL Console.
Return:
text
CarrierId
ConnectionId
RouteCode
DepartureTime
DeparturePeriodSort by:
text
CarrierId
ConnectionIdThen add a SQL Console filter for:
text
DeparturePeriod = MorningThis filter belongs to that query only.
Part 8 — Create a filtered CDS entity
Create:
text
ZI_MORNING_CONNECTION_###Its source must be:
text
ZI_CONNECTION_###not /DMO/CONNECTION.
Expose:
text
CarrierId
ConnectionId
AirportFromId
AirportToId
DepartureTime
ArrivalTime
Distance
DistanceUnit
RouteCode
DeparturePeriodAdd a CDS WHERE clause so the entity represents only Morning connections.
Use a typed character literal in the condition.
Part 9 — Activate and compare
Activate the filtered CDS entity.
Preview:
text
ZI_CONNECTION_###and:
text
ZI_MORNING_CONNECTION_###Answer:
1. Which entity contains all modeled connections?
2. Which entity contains only morning connections?
3. Which entity contains the CASE logic?
4. Does the filtered entity repeat the CASE expression?
It should not.
Part 10 — Create the Connection Reader
Create:
text
ZCL_CONNECTION_READER_###Define two internal-table types:
text
one based on ZI_CONNECTION_###
one based on ZI_MORNING_CONNECTION_###Use the CDS entities directly as global structured types.
Suggested names:
text
TT_CONNECTIONS
TT_MORNING_CONNECTIONSBoth should be standard tables with empty keys.
Part 11 — Add Reader methods
Create:
text
GET_ALL
GET_MORNINGGET_ALL returns all modeled connections.
GET_MORNING returns the morning-connection model.
Both methods should:
- use ABAP SQL;
- select from CDS, not the database table;
- sort by
CarrierIdandConnectionId.
Because each method returns the complete CDS entity type, FIELDS * is acceptable.
Part 12 — Create the Runner
Create:
text
ZCL_CDS_L03_PRACTICE_###Implement:
text
IF_OO_ADT_CLASSRUNIn main:
- create the Connection Reader;
- call
GET_ALL; - loop over the returned data;
- display:
text
RouteCode - DeparturePeriodThen call GET_MORNING and display the result.
The Runner should contain no direct:
abap
SELECT FROM /dmo/connectionPart 13 — Test the classification
Choose at least three connections if your data allows it:
text
one morning
one afternoon
one eveningRecord:
| DepartureTime | Expected | Actual |
|---|---|---|
If the demo data does not contain all three periods, use the periods that are present and state which category is absent.
Part 14 — Reasoning questions
1. What is the difference between a source field and a calculated CDS element?
2. Why is RouteCode defined once in CDS instead of concatenated in every Runner?
3. What does CASE do in this model?
4. What does WHERE do in the morning-connection model?
5. Why is abap.tims'120000' clearer than an untyped time-like literal?
6. Why does ZI_MORNING_CONNECTION_### select from ZI_CONNECTION_### instead of repeating all logic from /DMO/CONNECTION?
7. What is the difference between filtering in SQL Console and creating a filtered CDS View Entity?
8. Can a CDS View Entity be used as an ABAP type?
9. Why is FIELDS * acceptable in the Reader methods in this assignment?
10. Why is * not used in the CDS View Entity element list?
Optional challenge 1 — Evening model
Create:
text
ZI_EVENING_CONNECTION_###by reusing:
text
ZI_CONNECTION_###Filter:
text
DeparturePeriod = EveningDo not repeat the CASE expression.
Optional challenge 2 — Investigate another string function
Review the current CDS string-function documentation.
Add one additional calculated element using a different supported string function.
Document:
text
function used
input element(s)
example resultDo not use joins or associations.
Submission checklist
Useful ADT shortcuts
| Action | Shortcut |
|---|---|
| Open ABAP Development Object | Ctrl + Shift + A |
| Code completion | Ctrl + Space |
| 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 |