Skip to content

Lesson 2 Practice — Airport CDS Model ​

In Lesson 1 practice, the airport architecture was:

text
Runner
  ↓
Airport Reader
  ↓
ABAP SQL
  ↓
/DMO/AIRPORT

This assignment changes it to:

text
Runner
  ↓
Airport Reader
  ↓
ABAP SQL
  ↓
ZI_AIRPORT_###
  ↓
/DMO/AIRPORT

You will create the CDS model and refactor the Reader while keeping the Reader's public responsibility clear.

This assignment does not include the complete solution.


Objects ​

You will work with:

text
ZI_AIRPORT_###
ZCL_AIRPORT_READER_###
ZCL_SQL_L01_PRACTICE_###

If you completed the Lesson 1 Airport practice, reuse the existing Reader and Runner.

If those objects do not exist, create them using the Reader/Runner structure from Lesson 1 before completing the refactor sections.

Replace ###

Use your own student/group suffix in every object name.


Part 1 — Review the persistence source ​

Open:

text
/DMO/AIRPORT

Confirm these fields:

text
airport_id
name
city
country

Open Data Preview.

Record one airport ID and one country that exist in your system.

text
Airport ID:
Country:

Part 2 — Design the CDS model ​

Your CDS entity must expose:

Persistence fieldCDS element
airport_idAirportId
nameName
cityCity
countryCountry

Requirements:

  • entity name: ZI_AIRPORT_###;
  • source: /DMO/AIRPORT;
  • source alias: Airport;
  • AirportId is the CDS key;
  • include a readable end-user label;
  • set the tutorial entity's CDS authorization-check annotation to #NOT_REQUIRED.

Before writing code, sketch the model:

text
/DMO/AIRPORT
      ↓
ZI_AIRPORT_###
      ├─ AirportId
      ├─ Name
      ├─ City
      └─ Country

Part 3 — Create the Data Definition ​

In ADT:

  1. select your package;
  2. right-click;
  3. choose:
text
New
  → Other ABAP Repository Object
  → Core Data Services
  → Data Definition
  1. enter:
text
Name:        ZI_AIRPORT_###
Description: Lesson 2 - Airport CDS
  1. if Referenced Object is available, enter:
text
/DMO/AIRPORT
  1. select the course transport request if required;
  2. choose a CDS View Entity template;
  3. confirm the generated source uses:
abap
define view entity
  1. finish the wizard.

Part 4 — Implement the CDS View Entity ​

Write the CDS entity.

Required concepts:

text
@AccessControl.authorizationCheck
@EndUserText.label
define view entity
as select from
source alias
key
element aliases
Hint — Header and source
abap
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Airport'

define view entity ZI_Airport_###
  as select from /dmo/airport as Airport
{
  ...
}
Hint — Key

The first element begins:

abap
key Airport.airport_id as AirportId,

Do not open the lesson companion until you have made a serious attempt.


Part 5 — Use ADT code completion ​

Inside the element list:

  1. type:
abap
Airport.
  1. press:
text
Ctrl + Space
  1. use the completion list to add at least one source field.

This task is part of the assignment: use the tooling rather than typing every technical name from memory.


Part 6 — Check and activate ​

Run a syntax check:

text
Ctrl + F2

Fix all syntax errors.

Activate:

text
Ctrl + F3

The Data Definition must be active before the next tasks.


Part 7 — CDS Data Preview ​

With the cursor in the CDS source, press:

text
F8

Confirm the visible columns are:

text
AirportId
Name
City
Country

Answer:

1. Which names are visible: persistence names or CDS element names? ​

2. Did creating the CDS entity create a second copy of the airport records? ​


Part 8 — SQL Console ​

Open SQL Console.

Write a query against:

text
ZI_AIRPORT_###

Requirements:

  • select AirportId, Name, City, and Country;
  • sort by AirportId;
  • do not query /DMO/AIRPORT for this task.

Then add a filter using the country value recorded in Part 1.

The SQL Console result should use the CDS element names.


Part 9 — Inspect the existing Airport Reader ​

Open:

text
ZCL_AIRPORT_READER_###

Find the SQL in:

text
GET_ALL
GET_BY_COUNTRY
GET_BY_ID

Before modifying it, answer:

Which data source does the Reader currently use? ​

text
________________________

Which data source should it use after this assignment? ​

text
________________________

Part 10 — Refactor GET_ALL ​

Change the Reader so GET_ALL selects from:

text
ZI_AIRPORT_###

The Reader's existing public result structure uses names such as:

text
airport_id
name
city
country

The CDS entity exposes:

text
AirportId
Name
City
Country

Use ABAP SQL aliases so the Reader can keep its existing result contract.

Requirements:

  • source is ZI_AIRPORT_###;
  • fields come from the CDS entity;
  • result aliases match the Reader's existing structure;
  • order by AirportId;
  • no direct /DMO/AIRPORT SELECT remains in GET_ALL.
Hint

One field mapping has this form:

abap
AirportId AS airport_id

Part 11 — Refactor GET_BY_COUNTRY ​

Change GET_BY_COUNTRY.

Requirements:

  • source is ZI_AIRPORT_###;
  • the WHERE condition uses the CDS element Country;
  • the ABAP host variable still uses @;
  • output aliases preserve the Reader's existing result structure;
  • order by AirportId.

Part 12 — Refactor GET_BY_ID ​

Change GET_BY_ID.

Requirements:

  • use SELECT SINGLE;
  • source is ZI_AIRPORT_###;
  • use CDS element AirportId in the WHERE;
  • map CDS result elements to the Reader's existing result structure;
  • preserve the existing found handling.

Part 13 — Run the existing Runner ​

Open:

text
ZCL_SQL_L01_PRACTICE_###

Run it.

The Runner should continue calling the Airport Reader.

Confirm that:

  • all-airports output still works;
  • country filtering still works;
  • lookup by airport ID still works;
  • not-found handling still works.

Do not move the SQL into the Runner.


Part 14 — Prove the architecture ​

Draw or write the final dependency chain:

text
____________________
        ↓
____________________
        ↓
____________________
        ↓
____________________

The four layers should identify:

text
Runner
Reader
CDS View Entity
Database table

Part 15 — Reasoning questions ​

Answer in your own words.

1. What problem does the CDS layer solve that a direct table SELECT does not? ​

2. What is the difference between the Data Definition and the CDS View Entity? ​

3. What is the purpose of the source alias Airport? ​

4. Why does the CDS model expose AirportId instead of forcing every consumer to use airport_id? ​

5. What does the CDS key mean? ​

6. Why does the Reader use: ​

abap
AirportId AS airport_id

when reading the CDS entity?

7. Why can the Runner remain unchanged when the Reader changes from /DMO/AIRPORT to ZI_AIRPORT_###? ​

8. What is the difference between Data Preview, SQL Console, and the Reader? ​

9. Why is the Reader still useful after CDS has been introduced? ​

10. Why should new course CDS examples use define view entity instead of the older define view? ​


Optional challenge — Restrict the CDS model ​

Create a second CDS View Entity:

text
ZI_AIRPORT_BASIC_###

Expose only:

text
AirportId
Name
Country

Do not expose City.

Activate it and compare:

text
/DMO/AIRPORT Data Preview
ZI_AIRPORT_### Data Preview
ZI_AIRPORT_BASIC_### Data Preview

Answer:

Which layer decides what a CDS consumer can see?


Submission checklist ​


Useful ADT shortcuts ​

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