Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9159

Eliminating duplicated value (continued from scn...thread/3465567)

$
0
0

Dear Experts,

 

My thread is continued from this below :

 

http://scn.sap.com/thread/3465567

 

The latest query solution can't solve our company problem. Here is the query:

 

WITH receipt AS (

        SELECT distinct owor.ItemCode, oign.DocNum, ign1.BaseRef, SUM(ign1.LineTotal) AS total_receipt,

        ROW_NUMBER() OVER (partition by owor.docentry

ORDER BY owor.docentry) as row,owor.docentry

        FROM ign1 inner join OWOR on owor.DocEntry= IGN1.BaseEntry and ign1.ItemCode=owor.ItemCode

        inner join OIGN on oign.DocEntry=ign1.DocEntry and ign1.BaseType = '202'

        GROUP BY owor.ItemCode, ign1.baseref, oign.DocNum,oign.docentry,owor.DocEntry

     ),

     issued AS (

        SELECT owor.DocEntry,

        ROW_NUMBER() OVER (partition by owor.docentry

ORDER BY owor.docentry ) as iss_row,

          OIGe.DocNum, ige1.BaseRef, sum(Isnull(ige1.linetotal,0)) as total_issue

        FROM ige1 inner join OWOR on owor.DocEntry= ige1.BaseEntry and IGE1.BaseType = '202'

        inner join WOR1 on wor1.DocEntry = owor.DocEntry inner join OIGE on oige.DocEntry= ige1.DocEntry

                group by ige1.BaseRef, oige.DocNum,oige.docentry,owor.DocEntry

     )

 

select

TBL2.DocNum,TBL2.[FG-Code],TBL2.[Issued Num],Isnull(TBL2.[Issued Amt],0) [Issued Amt],TBL2.[Receipt Num],TBL2.[Receipt Amt]

  from (

Select (CASE rnum when 1 then ItemCode  end) [FG-Code],

(CASE rnum when 1 then Isnull(DocNum,0)  end) [DocNum],

(CASE ISrnum when 1 then Isnull(Issued_No,0)  end) [Issued Num],

(CASE ISrnum when 1 then Isnull(issuedamount,0)  end) [Issued Amt],

(CASE RSrnum when 1 then Isnull(Receipt_No,0)  end) [Receipt Num],

(CASE RSrnum when 1 then Isnull(receiptamount,0)  end) [Receipt Amt],

(forshort) [forshort]

 

 

from (   

SELECT owor.docentry,ROW_NUMBER() OVER (partition by owor.docentry order by owor.docentry) [rnum] ,

owor.docentry [forshort],

ROW_NUMBER() OVER (partition by issued.DocNum order by issued.DocNum) [ISrnum],

ROW_NUMBER() OVER (partition by receipt.DocNum order by receipt.DocNum) [RSrnum],

owor.ItemCode, owor.DocNum, issued.DocNum as Issued_No,

       max(Isnull(issued.total_issue,0)) AS issuedamount,

       receipt.DocNum as Receipt_No,

       max(receipt.total_receipt) AS receiptamount

FROM wor1 inner join owor on owor.DocEntry = wor1.docentry

left outer join receipt

on receipt.DocEntry = owor.DocEntry

left outer join issued

on issued.DocEntry = owor.DocEntry and Isnull(issued.iss_row,0) = Isnull(receipt.row,0)

where owor.DocNum = 154

GROUP BY owor.docentry,owor.ItemCode, owor.DocNum, issued.DocNum, receipt.DocNum,receipt.row ,issued.iss_row  ) TBL1 ) TBL2

group by

TBL2.DocNum,TBL2.[FG-Code],TBL2.[Issued Amt],TBL2.[Issued Num],TBL2.[Receipt Num],TBL2.[Receipt Amt]

 

 

order by

Max(TBL2.forshort) , TBL2.DocNum desc

 

 

the query result:

 

missing5.png

when I check the production order relationship map belows:

 

 

missing4.png

 

The issue is there is no return component document in the query result. Its no is 145.

 

Please help how to include the return component document. Thank you.

 

 

Rgds,
steve


Viewing all articles
Browse latest Browse all 9159

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>