Skip to content

Lesson 3 Practice — Connection Modeling ​

In Lesson 3, you created:

text
/DMO/FLIGHT
      ↓
ZI_FLIGHT_###
      ↓
calculated elements
      ↓
ZI_AVAILABLE_FLIGHT_###
      ↓
filtered model

In this practice, apply the same ideas to:

text
/DMO/CONNECTION

Your target architecture is:

text
/DMO/CONNECTION
      ↓
ZI_CONNECTION_###
  ├─ RouteCode
  └─ DeparturePeriod
      ↓
ZI_MORNING_CONNECTION_###
      ↓
Connection Reader
      ↓
Runner

This 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/CONNECTION

with:

text
Ctrl + Shift + A

Identify:

text
carrier_id
connection_id
airport_from_id
airport_to_id
departure_time
arrival_time
distance
distance_unit

Confirm that the key is:

text
carrier_id + connection_id

Open 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
DeparturePeriod

Two elements must be derived:

text
RouteCode
DeparturePeriod

Part 3 — Define RouteCode ​

Use the CDS built-in function:

text
CONCAT_WITH_SPACE

Combine:

text
AirportFromId
AirportToId

with one space between them.

Example result:

text
FRA JFK
Hint

The function shape is:

abap
concat_with_space(
  <first value>,
  <second value>,
  1
)

Answer:

Why is RouteCode a 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    → Evening

Use 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 DeparturePeriod

Part 5 — Create ZI_CONNECTION_### ​

Create a Data Definition.

Use:

text
Name:        ZI_CONNECTION_###
Description: Lesson 3 - Connection CDS

Source:

text
/DMO/CONNECTION

Source alias:

text
Connection

Requirements:

  • CarrierId is a key;
  • ConnectionId is 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 + Space

for code completion.


Part 6 — Check, activate, and preview ​

Run:

text
Ctrl + F2

Fix all syntax errors.

Activate:

text
Ctrl + F3

Preview:

text
F8

Verify 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
DeparturePeriod

Sort by:

text
CarrierId
ConnectionId

Then add a SQL Console filter for:

text
DeparturePeriod = Morning

This 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
DeparturePeriod

Add 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_CONNECTIONS

Both should be standard tables with empty keys.


Part 11 — Add Reader methods ​

Create:

text
GET_ALL
GET_MORNING

GET_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 CarrierId and ConnectionId.

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_CLASSRUN

In main:

  1. create the Connection Reader;
  2. call GET_ALL;
  3. loop over the returned data;
  4. display:
text
RouteCode - DeparturePeriod

Then call GET_MORNING and display the result.

The Runner should contain no direct:

abap
SELECT FROM /dmo/connection

Part 13 — Test the classification ​

Choose at least three connections if your data allows it:

text
one morning
one afternoon
one evening

Record:

DepartureTimeExpectedActual

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 = Evening

Do 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 result

Do not use joins or associations.


Submission checklist ​


Useful ADT shortcuts ​

ActionShortcut
Open ABAP Development ObjectCtrl + Shift + A
Code completionCtrl + Space
Syntax checkCtrl + F2
Activate current objectCtrl + F3
Activate inactive objectsCtrl + Shift + F3
CDS Data PreviewF8
Run console classF9
Format sourceShift + F1