Skip to content

Lesson 1 Practice — Airport Reader and Runner

In the lesson, you created:

text
Runner

Carrier Reader

/DMO/CARRIER

For this assignment, build the same structure for airports:

text
Runner

Airport Reader

/DMO/AIRPORT

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

Record:

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
country

Requirements:

  • select from /DMO/AIRPORT;
  • use an explicit FIELDS list;
  • 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 PUBLIC

It 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
country

Use the corresponding component types from /DMO/AIRPORT.

Then define a standard internal-table type for multiple airports using:

text
WITH EMPTY KEY

Suggested names:

text
TY_AIRPORT
TT_AIRPORTS

Part 5 — Implement GET_ALL

Add a Reader method:

text
GET_ALL

Requirements:

  • return your airport table type;
  • select from /DMO/AIRPORT;
  • use an explicit FIELDS list;
  • return airport_id, name, city, and country;
  • 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_CLASSRUN

In main:

  1. create an Airport Reader object;
  2. call GET_ALL;
  3. store the returned internal table;
  4. display it with out->write( ).

Your structure should be:

text
Runner

  │ GET_ALL

Reader

  │ SELECT

/DMO/AIRPORT

Part 7 — Implement GET_BY_COUNTRY

Add:

text
GET_BY_COUNTRY

Requirements:

  • 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 - Name

The Reader reads data. The Runner decides how to display it.

Part 9 — Implement GET_BY_ID

Add:

text
GET_BY_ID

It should receive:

text
airport_id

and provide:

text
airport
found

Requirements:

  • importing airport_id;
  • exporting airport using your row type;
  • exporting found as abap_bool;
  • use SELECT SINGLE;
  • use the complete key in the WHERE condition;
  • check sy-subrc immediately after the SQL;
  • set found = abap_true when the row exists.

Part 10 — Call GET_BY_ID

From the Runner:

  1. use the valid airport ID you recorded earlier;
  2. call GET_BY_ID;
  3. display the airport when found = abap_true;
  4. otherwise display Airport not found;
  5. test a non-existing airport ID too.

Part 11 — Architecture questions

  1. 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.

  2. Why does the Runner not contain the airport SELECT statements?

  3. What is the responsibility of the Reader?

  4. What is the responsibility of the Runner?

  5. Is ZCL_AIRPORT_READER_### a RAP business service? Explain.

  6. Why does ordinary ABAP SQL in this lesson not need a JDBC/ODBC-style connection string?

  7. Why does the Reader return typed ABAP data instead of writing directly to the console?

  8. Why is WHERE inside GET_BY_COUNTRY preferable to reading every airport and filtering in the Runner?

  9. Why is SELECT SINGLE appropriate for GET_BY_ID?

  10. Why is sy-subrc checked inside the Reader method rather than in the Runner?

Optional challenge

Add:

text
GET_BY_CITY

Requirements:

  • importing city parameter;
  • returning airport table;
  • WHERE city = @city;
  • ORDER BY airport_id.

Call it from the Runner.

Submission checklist

Useful ADT shortcuts

ActionShortcut
Open ABAP Development ObjectCtrl + Shift + A
Syntax checkCtrl + F2
Activate current objectCtrl + F3
Run console classF9
Code completionCtrl + Space

SQL Console can be opened from the ABAP project, Data Preview, or the table's Open With menu. | Format source | Shift + F1 |