ABAP中当需要同时查询多个表的相关字段时,需要使用到JOIN语句,跟平常数据库中用到的连接查询基本上相同。共包含三种:

      1)INNER JOIN:查询结果包含两个连接表中彼此相对应的数据记录。

      2)LEFT OUTER JOIN:查询结果集中包含左则表中的所有数据记录,右表中仅查询出包含相对应的匹配条件的数据。

      3)FULL OUTER JOIN:包含左右表所有的记录。

      [For Example]

      TABLES:SPFLI,SFLIGHT.
      DATA:BEGIN OF Xflight OCCURS 0,
               airpfrom LIKE SPFLI-Airpfrom,
               airpto LIKE SPFLI-Airpto,
               fldate LIKE SFLIGHT-Fldate,
              deptime LIKE SPFLI-Deptime,
      END OF Xflight.

     SELECT a~airpfrom a~airpto b~fldate a~deptime INTO CORRESPONDING FIELDS OF TABLE Xflight
     FROM SPFLI AS a INNER JOIN SFLIGHT AS b
     ON a~CARRID = b~CARRID AND a~CONNID = b~CONNID
     ORDER BY a~airpfrom a~airpto b~fldate a~deptime.

     LOOP AT Xflight.
        WRITE: / 'Airpfrom=', Xflight-Airpfrom,
                    / 'Airpto=', Xflight-Airpto.
    ENDLOOP.

    *查询结果如下图所示: