ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Open SQL → Open SQL - Read Accesses → SELECT → SELECT - WHERE → WHERE - sql_cond → sql_cond - subquery
Subqueries
The example demonstrates how subqueries can be used.
Other versions: 7.31 | 7.40 | 7.54
Source Code
REPORT demo_select_subquery.
DATA: wa TYPE sflight,
plane LIKE wa-planetype,
seats LIKE wa-seatsmax.
SELECT carrid, connid, planetype, seatsmax, MAX( seatsocc )
FROM sflight
GROUP BY carrid, connid, planetype, seatsmax
ORDER BY carrid, connid
INTO (@wa-carrid, @wa-connid, @wa-planetype,
@wa-seatsmax, @wa-seatsocc).
WRITE: / wa-carrid,
wa-connid,
wa-planetype,
wa-seatsmax,
wa-seatsocc.
HIDE: wa-carrid, wa-connid, wa-seatsmax.
ENDSELECT.
AT LINE-SELECTION.
WINDOW STARTING AT 45 3 ENDING AT 85 13.
WRITE: 'Alternative Plane Types',
'for', wa-carrid, wa-connid.
ULINE.
SELECT planetype, seatsmax
FROM saplane AS plane
WHERE seatsmax < @wa-seatsmax AND
seatsmax >= ALL ( select seatsocc
FROM sflight
WHERE carrid = @wa-carrid AND
connid = @wa-connid )
ORDER BY seatsmax
INTO (@plane, @seats).
WRITE: / plane, seats.
ENDSELECT.
Description
After selecting a flight, the secondary list displays all airplane types that are sufficient for a connection concerning the booking status but that have less seats than the current plane type.