abapopensql

Two select loops into single SELECT?


I have been learning abap recently and working on select operations but then I came across this question. How can I put these 2 select statements into single select statement?

SELECT * FROM SPFLI INTO SPFLI_WA.

      SELECT * FROM SFLIGHT INTO SFLIGHT_WA    
            WHERE CARRID = SPFLI_WA-CARRID    
             AND CONNID = SPFLI_WA-CONNID.

      ENDSELECT.

ENDSELECT.

Solution

  • You can use inner join for getting matching records from other table.

    SELECT SFLIGHT~*
      INTO @SFLIGHT_WA
      FROM SFLIGHT
     INNER JOIN SPFLI ON SFLIGHT~CARRID = SPFLI~CARRID
                       AND SFLIGHT~CONNID = SPFLI~CONNID.
    
    ENDSELECT.