How do I get Serial Number of and Item in invoice (INV1 and OSRI tables)
I am new to SAP development, bear with me if I make any mistake.
I am trying to get the serial number of an Item on an Invoice. The code I am using is
select T2.DocNum, T3.ItemCode as 'Item Number', s1.intrSerial as 'Serial Number',
T3.Dscription as description, T3.vendorNum as 'Vendor Model No',
T3.Quantity as 'Qty Sold',
T3.whscode as 'From Warehouse', lastpurprc as 'Last Purchase price',
O2.Price as 'MSRP', T3.Price as 'Sold price',
inDate as 'Date First Recd', convert(varchar(10),T2.DocDate,101) as 'Date Sold'
FROM OINV T2, INV1 T3,
OITM O1, ITM1 O2,OSRI S1
where T3.ItemCode = O1.ItemCode
and O1.ItemCode = O2.ItemCode
and T2.DocEntry = T3.DocEntry
and T2.DocNum ='2201'
and O2.pricelist =1
and O1.ItemCode = S1.ItemCode
and O2.ItemCode = S1.ItemCode
and convert(varchar(10),T2.DocDate,120) = '2008-09-01'
The problem is that I am getting 9 rows instead if 1 because there is no one-to-one relation to OSRI table which keeps the SerialNumber.
Please guide me
Hillary Mauerman replied
I did something very similar with ORDR to find a the serial numbers that were related to a sales order. Maybe this will help you:
SELECT distinct osri.IntrSerial FROM osri
JOIN sri1 ON dbo.SRI1.SysSerial = dbo.OSRI.SysSerial AND dbo.OSRI.ItemCode = sri1.ItemCode
JOIN odln ON dbo.odln.DocNum = dbo.SRI1.BaseNum
JOIN dbo.DLN1 ON odln.DocEntry = dln1.DocEntry
JOIN ordr ON dln1.BaseRef = ordr.DocNum
WHERE ordr.DocNum = [%0]
AND dbo.SRI1.CardCode = ordr.CardCode