今天写一个SD的程序,出了点小问题
原来的SQL语句如下
SELECT k~vbeln k~auart p~posnr k~audat p~matnr k~kunnr p~kwmeng
p~netpr p~kpein p~netwr k~waerk k~stwae d~bstkd
INTO TABLE gt_vbak
FROM vbak AS k
JOIN vbap AS p ON p~vbeln = k~vbeln
JOIN vbkd AS d ON d~vbeln = p~vbeln AND d~posnr = p~posnr
WHERE k~vtweg IN s_vtweg
AND k~audat IN s_audat
AND k~kunnr IN s_kunnr
AND k~auart IN s_auart.
但是数据库表VBKD和VBAP不一定是一一对应的
如有一张订单,在VBKD中有客户PO号码,但是对应的没有行项目号,这样写SQL语句就查找不出来,于是改用 LEFT JOIN,如下
SELECT k~vbeln k~auart p~posnr k~audat p~matnr k~kunnr p~kwmeng
p~netpr p~kpein p~netwr k~waerk k~stwae d~bstkd
INTO TABLE gt_vbak
FROM vbak AS k
JOIN vbap AS p ON p~vbeln = k~vbeln
* JOIN vbkd AS d ON d~vbeln = p~vbeln AND d~posnr = p~posnr
left JOIN vbkd AS d ON d~vbeln = p~vbeln AND d~posnr = p~posnr
WHERE k~vtweg IN s_vtweg
AND k~audat IN s_audat
AND k~kunnr IN s_kunnr
AND k~auart IN s_auart.
即可
另外inner join与join应该是一样的