Hi
we have this occur every couple of weeks or so. It is as if something has tried to post the same receipt twice. The incorrect receipt always has a line sequence number 1 greater than 16385,32769 etc.
I run the following code to remove.
This will fix goods receipts & transfers
If you have Lot/serial numbers it will not correct the lot number error.
--(1)set receipt number and show duplicated lines
declare @RECEIPTNUMBER as varchar(11)
SET @RECEIPTNUMBER = 'rct01509346'
select * from iv30300 with (nolock) where docnumbr = @RECEIPTNUMBER
order by lnseqnbr
select * from iv30301 with (nolock) where rcptnmbr = @RECEIPTNUMBER
order by lnseqnbr
--(2)drop temporary table and get information to update IV00102 QTYONHND
drop table wyn_dupreceipt
select doctype,itemnmbr,trxloctn,trnstloc,trxqty,qtybsuom,trxqty*qtybsuom as adjqty
into wyn_dupreceipt
from iv30300 where docnumbr = @RECEIPTNUMBER and lnseqnbr in (16385,32769,49153,65537,81921,98305,114689,131073,147457,163841,180225,196609,212993,229377,245761,262145,278529,294913,311297,327681,344065,360449,376833,393217,409601,425985,442369,458753,475137,491521,507905,524289,540673,557057,573441,589825,606209,622593,638977,655361,671745,688129,704513,720897,737281,753665,770049,786433,802817,819201,835585,851969,868353,884737,901121,917505,933889,950273,966657,983041,999425,1015809,1032193,1048577,1064961,1081345,1097729,1114113,1130497,1146881,1163265,1179649,1196033,1212417,1228801,1245185,1261569,1277953,1294337,1310721,1327105,1343489,1359873,1376257,1392641,1409025,1425409,1441793,1458177,1474561,1490945,1507329,1523713,1540097,1556481,1572865,1589249,1605633,1622017,1638401,1654785,1671169,1687553,1703937,1720321,1736705,1753089,1769473,1785857,1802241,1818625,1835009,1851393,1867777,1884161,1900545,1916929,1933313,1949697,1966081,1982465,1998849,2015233,2031617,2048001,2064385,2080769,2097153,2113537,2129921,2146305,2162689,2179073,2195457,2211841)
--(3) Delete duplicated lines
delete iv30300 where docnumbr = @RECEIPTNUMBER and lnseqnbr in (16385,32769,49153,65537,81921,98305,114689,131073,147457,163841,180225,196609,212993,229377,245761,262145,278529,294913,311297,327681,344065,360449,376833,393217,409601,425985,442369,458753,475137,491521,507905,524289,540673,557057,573441,589825,606209,622593,638977,655361,671745,688129,704513,720897,737281,753665,770049,786433,802817,819201,835585,851969,868353,884737,901121,917505,933889,950273,966657,983041,999425,1015809,1032193,1048577,1064961,1081345,1097729,1114113,1130497,1146881,1163265,1179649,1196033,1212417,1228801,1245185,1261569,1277953,1294337,1310721,1327105,1343489,1359873,1376257,1392641,1409025,1425409,1441793,1458177,1474561,1490945,1507329,1523713,1540097,1556481,1572865,1589249,1605633,1622017,1638401,1654785,1671169,1687553,1703937,1720321,1736705,1753089,1769473,1785857,1802241,1818625,1835009,1851393,1867777,1884161,1900545,1916929,1933313,1949697,1966081,1982465,1998849,2015233,2031617,2048001,2064385,2080769,2097153,2113537,2129921,2146305,2162689,2179073,2195457,2211841)
delete iv30301 where docnumbr = @RECEIPTNUMBER and lnseqnbr in (16385,32769,49153,65537,81921,98305,114689,131073,147457,163841,180225,196609,212993,229377,245761,262145,278529,294913,311297,327681,344065,360449,376833,393217,409601,425985,442369,458753,475137,491521,507905,524289,540673,557057,573441,589825,606209,622593,638977,655361,671745,688129,704513,720897,737281,753665,770049,786433,802817,819201,835585,851969,868353,884737,901121,917505,933889,950273,966657,983041,999425,1015809,1032193,1048577,1064961,1081345,1097729,1114113,1130497,1146881,1163265,1179649,1196033,1212417,1228801,1245185,1261569,1277953,1294337,1310721,1327105,1343489,1359873,1376257,1392641,1409025,1425409,1441793,1458177,1474561,1490945,1507329,1523713,1540097,1556481,1572865,1589249,1605633,1622017,1638401,1654785,1671169,1687553,1703937,1720321,1736705,1753089,1769473,1785857,1802241,1818625,1835009,1851393,1867777,1884161,1900545,1916929,1933313,1949697,1966081,1982465,1998849,2015233,2031617,2048001,2064385,2080769,2097153,2113537,2129921,2146305,2162689,2179073,2195457,2211841)
--(4)update qtyonhnd
-- goods receipt
UPDATE IV00102
SET QTYONHND = IV00102.QTYONHND - wyn_dupreceipt.adjqty
FROM wyn_dupreceipt INNER JOIN
IV00102 ON wyn_dupreceipt.itemnmbr = IV00102.ITEMNMBR AND wyn_dupreceipt.trxloctn = IV00102.LOCNCODE and doctype = 4
-- transfers ex location
UPDATE IV00102
SET QTYONHND = IV00102.QTYONHND + wyn_dupreceipt.adjqty
FROM wyn_dupreceipt INNER JOIN
IV00102 ON wyn_dupreceipt.itemnmbr = IV00102.ITEMNMBR AND wyn_dupreceipt.trxloctn = IV00102.LOCNCODE and doctype = 3
-- transfers to location
UPDATE IV00102
SET QTYONHND = IV00102.QTYONHND - wyn_dupreceipt.adjqty
FROM wyn_dupreceipt INNER JOIN
IV00102 ON wyn_dupreceipt.itemnmbr = IV00102.ITEMNMBR AND wyn_dupreceipt.TRNSTLOC = IV00102.LOCNCODE and doctype = 3
-- END