我遇到了问题。 目前我有三个表,第一个表是主表,如果第二个表中没有记录,也写它。但是如果第二个表中存在记录,那么从第三个表中显示" dispo"信息..
我想使用三个SAP表 - lagp,lqua和marc。 我的目标是写下所有来自lagp的股票头寸。
2x LEFT JOIN不起作用:"无法与" B~MATNR"进行比较。一个表可以与最多一个其他表联合使用LEFT OUTER JOIN。
结构:
TYPES:
BEGIN OF t_work,
lgnum TYPE lgnum,
lgtyp TYPE lgtyp,
lgpla TYPE lgpla,
bdatu TYPE lagp_bdatu,
matnr TYPE matnr,
verme TYPE lqua_verme,
meins TYPE meins,
dispo TYPE dispo,
END OF t_work.
DATA:
lt_work TYPE TABLE OF t_work INITIAL SIZE 0,
ls_work LIKE LINE OF lt_work.
和SQL命令:
SELECT a~lgnum a~lgtyp a~lgpla a~bdatu b~matnr b~verme b~meins c~dispo FROM lagp AS a
LEFT JOIN lqua AS b ON a~lgnum = b~lgnum AND a~lgtyp = b~lgtyp AND a~lgpla = b~lgpla
INNER JOIN marc AS c ON b~matnr = c~matnr AND b~werks = c~werks
INTO TABLE lt_work
WHERE a~lgnum IN so_lgnum
AND a~lgtyp IN so_lgtyp
AND a~skzua EQ space
AND a~skzue EQ space.
但结果只有一个股票仓位 - http://i.stack.imgur.com/1sEEo.png
你能告诉我,SQL代码看起来怎么样?
谢谢
答案 0 :(得分:0)
尝试:
SELECT a~lgnum, a~lgtyp, a~lgpla, a~bdatu, b~matnr, b~verme, b~meins, c~dispo
FROM lagp AS a
LEFT JOIN ( lqua AS b
JOIN marc AS c ON b~matnr = c~matnr AND b~werks = c~werks )
ON a~lgnum = b~lgnum AND a~lgtyp = b~lgtyp AND a~lgpla = b~lgpla
INTO TABLE @lt_work
WHERE a~lgnum IN @so_lgnum
AND a~lgtyp IN @so_lgtyp
AND a~skzua EQ @space
AND a~skzue EQ @space.
其他选项是将LQUA和MARC之间的连接放在视图中,并与视图进行外连接。或者在MARC上拆分选择并在循环使用LAGP和LQUA上的选择找到的数据时执行此操作。
答案 1 :(得分:0)
我得到了很好的工作代码:
SELECT ma~matnr ma~mtart ma~ernam ma~ersda ma~laeda
de~maktx as maktx_de fr~maktx as maktx_fr it~maktx as maktx_it
FROM mara as ma
LEFT JOIN MAKT as de ON de~matnr = ma~matnr AND de~spras = 'DE'
LEFT JOIN MAKT as fr ON fr~matnr = ma~matnr AND fr~spras = 'FR'
LEFT JOIN MAKT as it ON it~matnr = ma~matnr AND it~spras = 'IT'
INTO CORRESPONDING FIELDS OF TABLE g_it_material
WHERE ma~ernam IN so_ERNAM
AND ma~laeda IN so_LAEDA
AND ma~matnr IN so_MATNR.
它工作正常。你怎么说多左连接?