2017-09-15 63 views
1

看起來結果是程序僅通過AUART ='YI01'獲得所有銷售訂單(來自VBAK表),並且實際上我獲得了1.699.698的銷售訂單。所以它忽略了其他參數VTWEG = 'Z1',SPART = 'Z1',KUNNR = '0230001039', ERDAT = GT '01.09.2017'爲此,我只能得到77個結果。SELECT帶OR條件的錯誤結果

TYPES: BEGIN OF lw_odv_vbak, 
     vbeln TYPE vbak-vbeln, 
     vkorg TYPE vbak-vkorg, 
     vtweg TYPE vbak-vtweg, 
     spart TYPE vbak-spart, 
     netwr TYPE vbak-netwr, 
     kunnr TYPE vbak-kunnr, 
     erdat type vbak-erdat, 
     END OF lw_odv_vbak. 


DATA: it_odv_vbak TYPE STANDARD TABLE OF lw_odv_vbak INITIAL SIZE 0. 



SELECT vbeln 
    FROM vbak 
     INTO TABLE it_odv_vbak 
     WHERE vkorg = 'Z326' 
     AND vtweg = 'Z1' 
     AND spart = 'Z1' 
     AND kunnr = '0230001039' 
     AND auart = 'YC01' OR 
      auart = 'YI01' 
     AND erdat GT '01.09.2017'. 

非常感謝您的幫助

+0

如果你想成爲一名程序員,最好先了解邏輯。 – Jagger

+0

大家好, 感謝您的幫助,不幸的是我仍然得到錯誤的結果。 我想要做的是從VBAK表下面的參數提取: vkorg = 'Z326' vtweg = 'Z1' SPART = 'Z1' KUNNR = '0230001039' auart = 'YC01' OR auart ='YI01' erdat GT'20170901' – hammerman

回答

2

ANDOR更高的優先級,讓你有效地選擇用於

(vkorg = 'Z326' AND vtweg = 'Z1' AND spart = 'Z1' AND kund = '0230001039' AND auart = 'YC01') 
    OR 
(auart = 'YI01' AND erdet GT '01.09.2017') 

這肯定不是你打算做。在你的OR子句中使用括號。

1

圍繞OR

SELECT vbeln 
    FROM vbak 
     INTO TABLE it_odv_vbak 
     WHERE vkorg = 'Z326' 
     AND vtweg = 'Z1' 
     AND spart = 'Z1' 
     AND kunnr = '0230001039' 
     AND (auart = 'YC01' OR 
      auart = 'YI01') 
     AND erdat GT '01.09.2017'. 
3

你可以做兩件事情使用括號: 1)使用括號周圍或 2)更改日期格式爲 '20170901'。在db中,日期存儲爲YYYYMMDD。

SELECT vbeln 
FROM vbak 
    INTO TABLE it_odv_vbak 
    WHERE vkorg = 'Z326' 
    AND vtweg = 'Z1' 
    AND spart = 'Z1' 
    AND kunnr = '0230001039' 
    AND (auart = 'YC01' OR auart = 'YI01') 
    AND erdat GT '20170901'.