Code examples · Modern ABAP · Beginner
Interactive classic report: click a flight connection to see its flight dates (HIDE and AT LINE-SELECTION)
The problem
A report shows the flight connections.
How we solve it
- 1Basic listWRITE and HIDE
- 2User clicksAT LINE-SELECTION
- 3Detail listread and WRITE
The result
The basic list shows connections; a double-click opens the flight dates.
1. The requirement
A report shows the flight connections. When the user double-clicks a connection, a second list shows the flight dates of that connection with the free seats. Double-clicking a heading line must do nothing.
2. How we design it
In a classic list the screen is plain text, so the program does not know which database row a line belongs to. HIDE solves this: it stores the current value of a variable together with the line. When the user selects the line, the event AT LINE-SELECTION runs and the stored values are put back into the variables. The program then reads the detail data by those values.
Why we decided it this way
- 1Global variables for HIDEThe stored values come back into the same variables. They must live as long as the list, so they are declared at the top of the program, not inside the event.
- 2Clear them at the end of the basic listA heading line has no HIDE data. If the variables still hold the last row, a click on the heading would show the wrong detail.
- 3Count free seats in the programFree seats are max seats minus occupied seats. The detail list calculates them while it prints.
Before you start
- Demo flight data in SPFLI and SFLIGHT. Check with SE16N.
- Program name such as ZR_FLIGHT_DRILL created in SE38 (executable program).
3. The code, step by step
Step 1 of 3: Write the basic list and hide the key
A list of connections where each line remembers carrier and connection.
" Global variables that HIDE will store
REPORT zr_flight_drill.
DATA: g_carrid TYPE s_carr_id,
g_connid TYPE s_conn_id.
" WRITE a line, then HIDE the key
START-OF-SELECTION.
SELECT carrid, connid, cityfrom, cityto
FROM spfli
ORDER BY carrid, connid
INTO TABLE @DATA(conns)
UP TO 20 ROWS.
WRITE: / 'Connections (double-click a line)'.
ULINE.
LOOP AT conns INTO DATA(conn).
g_carrid = conn-carrid.
g_connid = conn-connid.
WRITE: / conn-carrid, conn-connid, conn-cityfrom, conn-cityto.
HIDE: g_carrid, g_connid.
ENDLOOP.
CLEAR: g_carrid, g_connid.
Part by part (plain text)
- Global variables that HIDE will store. g_carrid and g_connid are declared at the top, outside any event. S_CARR_ID and S_CONN_ID are the data elements of the flight model, so the variables have the same type as the table fields.
- WRITE a line, then HIDE the key. We read up to 20 connections and write one line for each. HIDE stores the current values of g_carrid and g_connid with that line. The heading is written before the loop; it has no HIDE data. The last statement clears the variables so a click on the heading finds nothing.
Open in the portal
The SAP objects named in this code are linked in the code above and listed here. Each opens its page in the SAP Library.
If it does not work
4. The final outcome
The basic list shows connections; a double-click opens the flight dates.
What you should see
Basic list: AA 0017 NEW YORK SAN FRANCISCO AA 0064 SAN FRANCISCO NEW YORK Detail list after clicking AA 0017: Flights of AA 0017 19.11.2026 free seats: 12
Try it and check the result
- Put the three parts together in order, activate and run with F8. The basic list appears.
- Double-click one connection line: the second list shows its flight dates. Press Back to return.
- Double-click the heading line: nothing happens, which proves that the CLEAR and CHECK work.
Common mistakes
- If you forget CLEAR after the loop, a click on the heading shows the details of the last connection.
- HIDE stores values per line, not per list. Write the HIDE immediately after the WRITE of that line.
- For real reports with many columns, sorting and export, an ALV grid is the better choice. Classic lists are still used for small drill-downs and in older programs you will maintain.
- AT PFnn is obsolete. Use AT LINE-SELECTION for clicks and AT USER-COMMAND for your own buttons.