Appearance
Lesson 1 Practice — Airport Reader and Runner
In the lesson, you created:
text
Runner
↓
Carrier Reader
↓
/DMO/CARRIERFor this assignment, build the same structure for airports:
text
Runner
↓
Airport Reader
↓
/DMO/AIRPORTThis assignment does not include the complete solution.
Replace ###
Use your own student/group suffix in all object names.
Objects to create
text
ZCL_AIRPORT_READER_###
ZCL_SQL_L01_PRACTICE_###Part 1 — Inspect /DMO/AIRPORT
Open /DMO/AIRPORT with ADT and use Data Preview.
Identify:
text
airport_id
name
city
countryRecord:
text
Key field:
One existing airport ID:
One existing country:Use values that actually exist in your system.
Part 2 — Test the query in SQL Console
Open the ADT SQL Console from /DMO/AIRPORT, Data Preview, or your ABAP project.
Write and run a query that returns:
text
airport_id
name
city
countryRequirements:
- select from
/DMO/AIRPORT; - use an explicit
FIELDSlist; - use
ORDER BY airport_id; - verify that the result contains airport records.
The SQL Console query does not need INTO TABLE because SQL Console displays its own result.
Keep the query available. The same selection logic will be placed in the Airport Reader.
Part 3 — Create the Airport Reader
Create:
text
ZCL_AIRPORT_READER_###The Reader should be:
text
PUBLIC
FINAL
CREATE PUBLICIt should not implement IF_OO_ADT_CLASSRUN.
Why? Because it is not the executable console class.
Part 4 — Define Reader result types
In the public section, define a structure type for one airport containing:
text
airport_id
name
city
countryUse the corresponding component types from /DMO/AIRPORT.
Then define a standard internal-table type for multiple airports using:
text
WITH EMPTY KEYSuggested names:
text
TY_AIRPORT
TT_AIRPORTSPart 5 — Implement GET_ALL
Add a Reader method:
text
GET_ALLRequirements:
- return your airport table type;
- select from
/DMO/AIRPORT; - use an explicit
FIELDSlist; - return
airport_id,name,city, andcountry; - use
ORDER BY airport_id; - write the SQL result into the returning table.
Do not use SELECT *.
Part 6 — Create the Runner
Create:
text
ZCL_SQL_L01_PRACTICE_###This class does implement:
text
IF_OO_ADT_CLASSRUNIn main:
- create an Airport Reader object;
- call
GET_ALL; - store the returned internal table;
- display it with
out->write( ).
Your structure should be:
text
Runner
│
│ GET_ALL
▼
Reader
│
│ SELECT
▼
/DMO/AIRPORTPart 7 — Implement GET_BY_COUNTRY
Add:
text
GET_BY_COUNTRYRequirements:
- importing country parameter;
- returning airport table;
WHERE country = @...;ORDER BY airport_id.
Call the method from the Runner using the country you recorded in Part 1.
Part 8 — Process returned data
In the Runner, loop over the result of GET_BY_COUNTRY.
Display:
text
AirportId - City - NameThe Reader reads data. The Runner decides how to display it.
Part 9 — Implement GET_BY_ID
Add:
text
GET_BY_IDIt should receive:
text
airport_idand provide:
text
airport
foundRequirements:
- importing
airport_id; - exporting
airportusing your row type; - exporting
foundasabap_bool; - use
SELECT SINGLE; - use the complete key in the
WHEREcondition; - check
sy-subrcimmediately after the SQL; - set
found = abap_truewhen the row exists.
Part 10 — Call GET_BY_ID
From the Runner:
- use the valid airport ID you recorded earlier;
- call
GET_BY_ID; - display the airport when
found = abap_true; - otherwise display
Airport not found; - test a non-existing airport ID too.
Part 11 — Architecture questions
What is the difference between running the airport query in SQL Console and putting the query in the Airport Reader? Answer in your own words.
Why does the Runner not contain the airport
SELECTstatements?What is the responsibility of the Reader?
What is the responsibility of the Runner?
Is
ZCL_AIRPORT_READER_###a RAP business service? Explain.Why does ordinary ABAP SQL in this lesson not need a JDBC/ODBC-style connection string?
Why does the Reader return typed ABAP data instead of writing directly to the console?
Why is
WHEREinsideGET_BY_COUNTRYpreferable to reading every airport and filtering in the Runner?Why is
SELECT SINGLEappropriate forGET_BY_ID?Why is
sy-subrcchecked inside the Reader method rather than in the Runner?
Optional challenge
Add:
text
GET_BY_CITYRequirements:
- importing city parameter;
- returning airport table;
WHERE city = @city;ORDER BY airport_id.
Call it from the Runner.
Submission checklist
Useful ADT shortcuts
| Action | Shortcut |
|---|---|
| Open ABAP Development Object | Ctrl + Shift + A |
| Syntax check | Ctrl + F2 |
| Activate current object | Ctrl + F3 |
| Run console class | F9 |
| Code completion | Ctrl + Space |
SQL Console can be opened from the ABAP project, Data Preview, or the table's Open With menu. | Format source | Shift + F1 |