我正在尝试在SAP HANA查询中加入ORDR
,ODLN
和OINV
,但我似乎无法找到他们共同分享的字段。
某处必须有一些记录可以将这些记录链接到另一个。
它们是通过单独的表链接的吗?或者我错过了一些明显的东西?
答案 0 :(得分:0)
请检查https://archive.sap.com/discussions/thread/1440163 有以下关系
SELECT Distinct(T0.DocNum ),T0.DocDate, T0.CardCode, T0.CardName, T1.ItemCode, T1.Quantity, T1.Price,T1.TotalSumSy, T0.DocTotal
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN ODLN T2 ON T2.DocEntry = T1.TrgetEntry
INNER JOIN DLN1 T3 on T3.DocEntry = T2.Docentry
INNER JOIN OINV T4 ON T4.DocEntry = T3.TrgetEntry
INNER JOIN INV1 T5 ON T5.DocEntry = T4.DocEntry
LEFT JOIN ORDN T6 ON T6.DocEntry = T5.TrgetEntry
LEFT JOIN RDN1 T7 ON T7.DocEntry = T6.DocEntry
所以跟随关系也是如此
SELECT *
FROM ODLN T2
INNER JOIN DLN1 T3 on T3.DocEntry = T2.Docentry
INNER JOIN OINV T4 ON T4.DocEntry = T3.TrgetEntry
答案 1 :(得分:0)
首先,归功于Eralper的答案,因为其中包含的链接帮助我找到了我想要的解决方案。但是,他们的解决方案不包括解释,也没有给出正在寻找的结果。
SAP销售订单的主要信息存储在两个表ORDR
和RDR1
中。 ORDR
每个销售订单都有一行,而RDR1
在销售订单上的每个产品行都有一行。
交货单和发票(基本上是SAP中的任何文档)都遵循这种模式。
为什么这个问题很重要?因为包含要链接销售订单,交货单和发票的数据的列位于RDR1
(或类似的变体)中。它的名字是TrgetEntry
。
由于销售订单上的每个产品都有一行,我们不能简单地进行连接,因为任何具有多个产品的销售订单都会在结果中多次出现。以下查询使用分组来显示每个销售订单都有一行的表,并具有将其链接到交货单的所需信息。
SELECT T0."DocEntry" AS "SO DE", T0."DocNum" AS "Sales Order Number", T1."TrgetEntry" AS "SO TE", COUNT(T0."DocNum") AS "Rows"
FROM ORDR T0
LEFT JOIN RDR1 T1 ON T0."DocEntry" = T1."DocEntry"
GROUP BY T0."DocEntry", T0."DocNum", T1."TrgetEntry"
只需更改表名,就可以为Delivery Notes和Invoices创建类似的查询。
然后,您可以使用TrgetEntry
和DocEntry
来链接各种结果。
我用来显示销售订单的最终代码,相关的交货和发票如下:
SELECT S0."SalesOrderNumber", S1."DeliveryNumber", S2."DocNum" AS "InvoiceNumber", S0."Rows", S2."DocTotal"
FROM (SELECT T0."DocEntry" AS "SO_DE", T0."DocNum" AS "SalesOrderNumber", T1."TrgetEntry" AS "SO_TE", COUNT(T0."DocNum") AS "Rows"
FROM ORDR T0
LEFT JOIN RDR1 T1 ON T0."DocEntry" = T1."DocEntry"
GROUP BY T0."DocEntry", T0."DocNum", T1."TrgetEntry") S0
LEFT JOIN (SELECT T0."DocEntry" AS "DN_DE", T0."DocNum" AS "DeliveryNumber", T1."TrgetEntry" AS "DN_TE"
FROM ODLN T0
LEFT JOIN DLN1 T1 ON T0."DocEntry" = T1."DocEntry"
GROUP BY T0."DocEntry", T0."DocNum", T1."TrgetEntry") S1 ON S0."SO_TE" = S1."DN_DE"
LEFT JOIN OINV S2 ON S1."DN_TE" = S2."DocEntry"