在子查询中选择多个字段

Selecting multiple fields in subquery

此 ABAP 代码有效:

  select *
   into table <sub_result>
  from ADRC
  WHERE ADDRNUMBER
  in ( select ADRNRA from AUFK where (cond_string) ).

但这不是:

  select *
   into table <sub_result>
  from ADRC
  WHERE (ADDRNUMBER, MANDT)
  in ( select ADRNRA, MANDT from AUFK where (cond_string) ).

据我所知,元组语法 (ADDRNUMBER, MANDT) 对 SQL 有效。这在 ABAP 的 Open SQL 中无效吗?

如果不允许使用元组语法,我该怎么办?

P.S. 在 Open SQL 中不需要检查 MANDT,因此这只是示例查询。

您不能将 in 用于多列。像这样尝试:

SELECT *
  INTO table <sub_result>
  FROM ADRC d
  WHERE exists ( select 1 from AUFK a where a~ADDRNUMBER = d~ADDRNUMBER and a~MANDT = d~MANDT)

为了完成 Pelin 的回答,这里有两种可能的语法,具体取决于 ABAP 版本:

DATA sflights TYPE TABLE OF sflight.

" Strict mode of OpenSQL (>= 7.40 SP 5 ; more syntaxes than old OpenSQL syntax)

SELECT * FROM sflight AS f INTO TABLE @sflights  " <== @ activates the strict mode
  WHERE NOT EXISTS ( SELECT 1 FROM sbook AS b    " <== 1 is possible in strict mode
        WHERE b~carrid = f~carrid
          AND b~connid = f~connid
          AND b~fldate = f~fldate ).

" "Loose" mode of OpenSQL (strict mode not used)

SELECT * FROM sflight AS f INTO TABLE sflights " <== no @ i.e. strict mode deactivated
  WHERE NOT EXISTS ( SELECT * FROM sbook AS b  " <== 1 is not possible
        WHERE b~carrid = f~carrid
          AND b~connid = f~connid
          AND b~fldate = f~fldate ).