两个 select 循环成单个 SELECT?

Two select loops into single SELECT?

我最近一直在学习 abap 并致力于 select 操作,但后来我遇到了这个问题。如何将这 2 个 select 语句放入单个 select 语句中?

SELECT * FROM SPFLI INTO SPFLI_WA.

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

      ENDSELECT.

ENDSELECT.

您可以使用内部联接从其他 table.

获取匹配记录
SELECT SFLIGHT~*
  INTO @SFLIGHT_WA
  FROM SFLIGHT
 INNER JOIN SPFLI ON SFLIGHT~CARRID = SPFLI~CARRID
                   AND SFLIGHT~CONNID = SPFLI~CONNID.

ENDSELECT.

这里是mkysoft对正确答案的扩展,只是为了好玩,完全模仿原始代码;它适用于 ABAP 7.40:

SELECT *
      INTO @DATA(spfli_sflight_wa)
      FROM spfli
      INNER JOIN sflight ON sflight~carrid = spfli~carrid
                        AND sflight~connid = spfli~connid.

  DATA(spfli_wa) = spfli_sflight_wa-spfli.
  DATA(sflight_wa) = spfli_sflight_wa-sflight.

  ...

ENDSELECT.