Appearance
Lesson 2 Practice — Airport CDS Model
In Lesson 1 practice, the airport architecture was:
text
Runner
↓
Airport Reader
↓
ABAP SQL
↓
/DMO/AIRPORTThis assignment changes it to:
text
Runner
↓
Airport Reader
↓
ABAP SQL
↓
ZI_AIRPORT_###
↓
/DMO/AIRPORTYou 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/AIRPORTConfirm these fields:
text
airport_id
name
city
countryOpen 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 field | CDS element |
|---|---|
airport_id | AirportId |
name | Name |
city | City |
country | Country |
Requirements:
- entity name:
ZI_AIRPORT_###; - source:
/DMO/AIRPORT; - source alias:
Airport; AirportIdis 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
└─ CountryPart 3 — Create the Data Definition
In ADT:
- select your package;
- right-click;
- choose:
text
New
→ Other ABAP Repository Object
→ Core Data Services
→ Data Definition- enter:
text
Name: ZI_AIRPORT_###
Description: Lesson 2 - Airport CDS- if Referenced Object is available, enter:
text
/DMO/AIRPORT- select the course transport request if required;
- choose a CDS View Entity template;
- confirm the generated source uses:
abap
define view entity- 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 aliasesHint — 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:
- type:
abap
Airport.- press:
text
Ctrl + Space- 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 + F2Fix all syntax errors.
Activate:
text
Ctrl + F3The Data Definition must be active before the next tasks.
Part 7 — CDS Data Preview
With the cursor in the CDS source, press:
text
F8Confirm the visible columns are:
text
AirportId
Name
City
CountryAnswer:
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, andCountry; - sort by
AirportId; - do not query
/DMO/AIRPORTfor 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_IDBefore 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
countryThe CDS entity exposes:
text
AirportId
Name
City
CountryUse 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/AIRPORTSELECT remains inGET_ALL.
Hint
One field mapping has this form:
abap
AirportId AS airport_idPart 11 — Refactor GET_BY_COUNTRY
Change GET_BY_COUNTRY.
Requirements:
- source is
ZI_AIRPORT_###; - the
WHEREcondition uses the CDS elementCountry; - 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
AirportIdin theWHERE; - map CDS result elements to the Reader's existing result structure;
- preserve the existing
foundhandling.
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 tablePart 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_idwhen 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
CountryDo not expose City.
Activate it and compare:
text
/DMO/AIRPORT Data Preview
ZI_AIRPORT_### Data Preview
ZI_AIRPORT_BASIC_### Data PreviewAnswer:
Which layer decides what a CDS consumer can see?
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 all inactive objects | Ctrl + Shift + F3 |
| CDS Data Preview | F8 |
| Run console class | F9 |
| Format source | Shift + F1 |