to:lzhan
1)全称:就是低阶码(Low Level Code,LLC)吧!
2)关于MRP展开运算特别是低阶码的运用,我也想知道!
好象是用来计算"净需求"时避免错误的,具体我也
不知道如何使用,
3)郭玉梁 大侠有段代码,我还没有研究清楚,你看看能否搞清,告诉我一声,
CREATE PROCEDURE [Dmwora]
AS
DECLARE @BookC VARCHAR(48), @ItemC VARCHAR(48), @WorkS VARCHAR(48),@LCode INTEGER, @LTime INTEGER, @GDate DATETIME, @DateC DATETIME, @DateI DATETIME, @Quant FLOAT
--设置初始数据
SET NOCOUNT ON
BEGIN TRANSACTION
TRUNCATE TABLE Mmfrom
DECLARE Mmtemp CURSOR LOCAL FOR SELECT DISTINCT BookC, ItemC FROM Mmitem WHERE State IN ('确定')
SELECT ItemC, LTime AS LCode INTO #Temp1 FROM Dmitem WHERE ItemC IS NULL
SELECT ItemC INTO #Temp2 FROM #Temp1
--确定生产计划
OPEN Mmtemp
FETCH NEXT FROM Mmtemp INTO @BookC, @ItemC WHILE @@FETCH_STATUS = 0
BEGIN
--计算低 层 码
TRUNCATE TABLE #Temp1
INSERT #Temp1 VALUES(@ItemC, 0)
SET @LCode = 0
WHILE 1 = 1
BEGIN
TRUNCATE TABLE #Temp2
SET @LCode = @LCode + 1
INSERT #Temp2 SELECT CItem FROM Dmstru WHERE PItem IN (SELECT ItemC FROM #Temp1 WHERE LCode = @LCode - 1)
DELETE #Temp1 WHERE ItemC IN (SELECT ItemC FROM #Temp2)
INSERT #Temp1 SELECT ItemC, @LCode FROM #Temp2
IF (SELECT COUNT(*) FROM #Temp2) = 0
BREAK
IF @LCode = 18 BEGIN RAISERROR ('产品结构有首尾相连,产生循环。', 15, 1)
ROLLBACK RETURN END
END
--计算需求数量
DECLARE Mmtemq CURSOR LOCAL FOR SELECT ItemC, LCode FROM #Temp1 ORDER BY LCode
OPEN Mmtemq
FETCH NEXT FROM Mmtemq INTO @ItemC, @LCode
WHILE @@FETCH_STATUS = 0
BEGIN
--加入生产计划
IF @LCode = 0
BEGIN
SELECT @LTime = LTime FROM Dmitem WHERE ItemC = @ItemC
SELECT @GDate = GDate, @Quant = Quant FROM Mmitem WHERE BookC = @BookC
INSERT Mmfrom (BookC, ItemC, DateC, QuanR, QuanN, QuanO, State)
VALUES(@BookC, @ItemC, @GDate, @Quant, @Quant, @Quant, '计划')
--生产计划投入
DECLARE Mmtemr CURSOR LOCAL FOR SELECT DateC, WorkS FROM Mmdate WHERE DateC <= @GDate AND WorkS <> '正常休息' ORDER BY DateC DESC
OPEN Mmtemr
FETCH NEXT FROM Mmtemr INTO @DateI, @WorkS
WHILE @@FETCH_STATUS = 0
BEGIN
IF @LTime = 0
BEGIN
UPDATE Mmfrom SET DateI = @DateI WHERE BookC = @BookC AND ItemC = @ItemC AND DateC = @GDate
INSERT Mmfrom (BookC, ItemC, DateC, QuanI, State) VALUES (@BookC, @ItemC, @DateI, @Quant, '计划')
BREAK
END
SET @LTime = @LTime - 1
FETCH NEXT FROM Mmtemr INTO @DateI, @WorkS
END
CLOSE Mmtemr DEALLOCATE Mmtemr
END
--计算需求计划
DECLARE Mmtemr CURSOR LOCAL FOR SELECT DateC, QuanI * Quant AS QuanI FROM Mmfrom, Dmstru
WHERE QuanI > 0 AND BookC = @BookC AND ItemC = PItem AND @ItemC = CItem
OPEN Mmtemr FETCH NEXT FROM Mmtemr INTO @DateC, @Quant
WHILE @@FETCH_STATUS = 0
BEGIN
--加入需求计划
IF NOT EXISTS(SELECT * FROM Mmfrom WHERE BookC = @BookC AND ItemC = @ItemC AND DateC = @DateC)
INSERT Mmfrom (BookC, ItemC, DateC, QuanR, QuanN, QuanO, State)
VALUES(@BookC, @ItemC, @DateC, @Quant, @Quant, @Quant, '计划') ELSE
UPDATE Mmfrom SET QuanR = QuanR + @Quant, QuanN = QuanN + @Quant, QuanO = QuanO + @Quant
WHERE BookC = @BookC AND ItemC = @ItemC AND DateC = @DateC
--需求计划投入
SELECT @LTime = LTime FROM Dmitem WHERE ItemC = @ItemC DECLARE Mmtems CURSOR LOCAL FOR
SELECT DateC, WorkS FROM Mmdate WHERE DateC <= @DateC AND WorkS <> '正常休息' ORDER BY DateC DESC
OPEN Mmtems FETCH NEXT FROM Mmtems INTO @DateI, @WorkS WHILE @@FETCH_STATUS = 0
BEGIN
IF @LTime = 0
BEGIN
UPDATE Mmfrom SET DateI = @DateI WHERE BookC = @BookC AND ItemC = @ItemC AND DateC = @DateC
IF NOT EXISTS(SELECT * FROM Mmfrom WHERE BookC = @BookC AND ItemC = @ItemC AND DateC = @DateI)
INSERT Mmfrom (BookC, ItemC, DateC, QuanI, State) VALUES (@BookC, @ItemC, @DateI, @Quant, '计划') ELSE
UPDATE Mmfrom SET QuanI = QuanI + @Quant WHERE BookC = @BookC AND ItemC = @ItemC AND DateC = @DateC
BREAK
END
SET @LTime = @LTime - 1 FETCH NEXT FROM Mmtems INTO @DateI, @WorkS
END CLOSE Mmtems DEALLOCATE Mmtems
--计算下一父项
FETCH NEXT FROM Mmtemr INTO @DateC, @Quant
END CLOSE Mmtemr DEALLOCATE Mmtemr
--计算下一物料
FETCH NEXT FROM Mmtemq INTO @ItemC, @LCode
END CLOSE Mmtemq DEALLOCATE Mmtemq
--计算下一计划
FETCH NEXT FROM Mmtemp INTO @BookC, @ItemC
END CLOSE Mmtemp DEALLOCATE Mmtemp
--需求计算完毕
DELETE Mmfrom WHERE ItemC IN (SELECT ItemC FROM Dmitem WHERE TypeD IN ('虚拟'))
COMMIT TRANSACTION