0

我设法通过更多选择和循环来进行选择。4张表(最后一张仅用于收集所有数据)

但现在我正在考虑一种方法,只需一个选择语句即可选择我需要的所有字段。这是巨大的选择:)

  SELECT vbak~vbeln vbak~audat
         tvakt~bezei
         vbap~posnr vbap~matnr vbap~kwmeng vbap~vrkme
         lips~vbeln lips~posnr lips~werks lips~lfimg
         vbfa~vbtyp_n
    FROM vbak JOIN vbap ON vbak~vbeln = vbap~vbeln
              JOIN tvakt ON vbak~auart = tvakt~auart
              LEFT JOIN vbfa ON vbfa~vbelv = vbak~vbeln AND vbfa~posnv = vbap~posnr
              JOIN lips ON vbfa~vbeln = lips~vbeln AND vbfa~posnn = lips~posnr
    INTO TABLE gt_salord
    WHERE tvakt~spras = 'EN' AND
          vbak~vbeln IN s_vbeln AND
          vbak~audat IN s_audat.

问题是这行不通。当我尝试激活它时会抛出此错误:“无法与“VBAP~POSNR”进行比较。使用 LEFT OUTER JOIN 最多可以将一个表与另一个表连接“如果我不使用 LEFT JOIN 而只加入它工作,但我没有得到我想要的所有东西。我需要得到所有的销售订单,即使他们没有分配交货订单。有没有办法做到这一点,还是我真的必须拆分我的选择?

4

4 回答 4

1

I have noticed in SAP that it's more efficient to simplify select statements and proceed with LOOP and SELECT SINGLE for table that do not participate in data selection.

In your case data from table VBFA could be fetch after data selection (it is not restricting the amount of data fetched from the DB).

Of course it depends on indexes, application server buffering... but, even though it might be counter-intuitive for SQL experts, keeping select statements not too complex in SAP is best.

于 2012-04-17T10:30:03.710 回答
1

您可以尝试以下选择:

SELECT vbak~vbeln vbak~audat
       tvakt~bezei
       vbap~posnr vbap~matnr vbap~kwmeng vbap~vrkme
       lips~vbeln lips~posnr lips~werks lips~lfimg
       vbfa~vbtyp_n
  FROM vbak JOIN vbap ON vbak~vbeln = vbap~vbeln
            JOIN tvakt ON vbak~auart = tvakt~auart
            LEFT JOIN vbfa ON vbfa~vbelv = vbap~vbeln AND vbfa~posnv = vbap~posnr
            JOIN lips ON vbfa~vbeln = lips~vbeln AND vbfa~posnn = lips~posnr
  INTO TABLE gt_salord
  WHERE tvakt~spras = 'EN' AND
        vbak~vbeln IN s_vbeln AND
        vbak~audat IN s_audat.

我无法测试结果,但语法检查说:好的。

只有一个微小的区别:

                                                  x---- difference
                                                  v
                LEFT JOIN vbfa ON vbfa~vbelv = vbap~vbeln AND vbfa~posnv = vbap~posnr 
                LEFT JOIN vbfa ON vbfa~vbelv = vbak~vbeln AND vbfa~posnv = vbap~posnr

vbfa~vbelv跟比vbak~vbeln,我跟vbap~vbeln。两者具有相同的值,但在 -on子句中您再次使用vbap

于 2012-04-13T11:38:28.330 回答
0

我不知道 SAP Abap 。但从 SQL 的角度来看,如果 SAP 支持派生查询,则可以使用它。

这是一些方法:

select * from
(
select * from
table1 inner join table2 on table1.key=table2.key
inner join table3 on table1.key=table3.key
) a left outer join table4 b 
on a.key=b.key

将此作为问题发布被标记为 SQL。希望它有效

于 2012-04-12T06:28:37.083 回答
-1

尝试改变left join的on子句中表字段的顺序。把 vbap~vbeln = vbfa~vbelv

于 2012-08-22T19:52:12.097 回答