Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP - Database Accesses →  Open SQL →  Open SQL - Read Accesses →  SELECT →  SELECT - cond →  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 )
  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.