SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
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.
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 )
INTO (wa-carrid, wa-connid, wa-planetype,
wa-seatsmax, wa-seatsocc)
FROM sflight
GROUP BY carrid connid planetype seatsmax
ORDER BY carrid connid.
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
INTO (plane, seats)
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.
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.