设置基于存储过程的次级向下钻取
次级向下钻取在从小计数据计算关键编号且需要访问此小计明细的情况下非常有用。可使用父级向下钻取的“输出列”属性名称作为次级向下钻取的输入参数。
预配置存货值关键编号是基于存储过程的关键编号的良好次级详查示例。此关键编号显示您的整个存货值,按存货详查至小计。它进一步详查至物料合计或按仓库详查至货位。
要将新详查作为次级详查关联:
例如:
一级详查程序:
SSSWBCanInvValItemDtlSp
CREATE PROCEDURE SSSWBCanInvValItemDtlSp (
@AsOfDate DateType
, @DrillNum WBDrillNumType
, @CrNum WBCrNumType
, @Id nvarchar(500)
, @Parm1 WBSourceNameType
, @Parm2 WBSourceNameType
, @Parm3 WBSourceNameType
, @Parm4 WBSourceNameType
, @Parm5 WBSourceNameType
, @Parm6 WBSourceNameType
, @Parm7 WBSourceNameType
, @Parm8 WBSourceNameType
, @Parm9 WBSourceNameType
, @Parm10 WBSourceNameType
, @Parm11 WBSourceNameType
, @Parm12 WBSourceNameType
, @Parm13 WBSourceNameType
, @Parm14 WBSourceNameType
, @Parm15 WBSourceNameType
, @Parm16 WBSourceNameType
, @Parm17 WBSourceNameType
, @Parm18 WBSourceNameType
, @Parm19 WBSourceNameType
, @Parm20 WBSourceNameType
, @Parm21 WBSourceNameType
, @Parm22 WBSourceNameType
, @Parm23 WBSourceNameType
, @Parm24 WBSourceNameType
, @Parm25 WBSourceNameType
, @Parm26 WBSourceNameType
, @Parm27 WBSourceNameType
, @Parm28 WBSourceNameType
, @Parm29 WBSourceNameType
, @Parm30 WBSourceNameType
, @Parm31 WBSourceNameType
, @Parm32 WBSourceNameType
, @Parm33 WBSourceNameType
, @Parm34 WBSourceNameType
, @Parm35 WBSourceNameType
, @Parm36 WBSourceNameType
, @Parm37 WBSourceNameType
, @Parm38 WBSourceNameType
, @Parm39 WBSourceNameType
, @Parm40 WBSourceNameType
, @Parm41 WBSourceNameType
, @Parm42 WBSourceNameType
, @Parm43 WBSourceNameType
, @Parm44 WBSourceNameType
, @Parm45 WBSourceNameType
, @Parm46 WBSourceNameType
, @Parm47 WBSourceNameType
, @Parm48 WBSourceNameType
, @Parm49 WBSourceNameType
, @Parm50 WBSourceNameType
) AS
DECLARE
@RowPointer RowPointer
, @TmpAmount AmountType
, @StartItem ItemType
, @EndItem ItemType
DECLARE @ttItemloc TABLE (
RowPointer uniqueidentifier
, item nvarchar(30)
, amount decimal(20,8)
, processed tinyint
)
SET @StartItem = ISNULL(@Parm1, dbo.LowString('ItemType'))
SET @EndItem = ISNULL(@Parm1, dbo.HighString('ItemType'))
INSERT INTO @ttItemloc
SELECT RowPointer, item, 0, 0
FROM itemloc
WHERE item BETWEEN @StartItem AND @EndItem
WHILE EXISTS (SELECT TOP 1 1 FROM @ttItemloc WHERE processed = 0)
BEGIN
SELECT TOP 1 @RowPointer = RowPointer
FROM @ttItemloc
WHERE processed = 0
SET @TmpAmount = 0
EXEC SSSWBCanInvValSubItemlocSp @RowPointer, @TmpAmount OUTPUT
UPDATE @ttItemloc
SET amount = @TmpAmount
, processed = 1
WHERE RowPointer = @RowPointer
END
INSERT INTO #tt_drill_results(
CHAR01, DECI01, amount
)
SELECT item, SUM(amount), SUM(amount)
FROM @ttItemloc
GROUP BY item
UPDATE #tt_drill_results
SET RowPointer = item.RowPointer
FROM #tt_drill_results tt, item
WHERE item.item = tt.CHAR01
RETURN 0
次级详查程序:
SSSWBCanInvValItemDtlSp
CREATE PROCEDURE SSSWBCanInvValDtlSp (
@AsOfDate DateType
, @DrillNum WBDrillNumType
, @CrNum WBCrNumType
, @Id nvarchar(500)
, @Parm1 WBSourceNameType
, @Parm2 WBSourceNameType
, @Parm3 WBSourceNameType
, @Parm4 WBSourceNameType
, @Parm5 WBSourceNameType
, @Parm6 WBSourceNameType
, @Parm7 WBSourceNameType
, @Parm8 WBSourceNameType
, @Parm9 WBSourceNameType
, @Parm10 WBSourceNameType
, @Parm11 WBSourceNameType
, @Parm12 WBSourceNameType
, @Parm13 WBSourceNameType
, @Parm14 WBSourceNameType
, @Parm15 WBSourceNameType
, @Parm16 WBSourceNameType
, @Parm17 WBSourceNameType
, @Parm18 WBSourceNameType
, @Parm19 WBSourceNameType
, @Parm20 WBSourceNameType
, @Parm21 WBSourceNameType
, @Parm22 WBSourceNameType
, @Parm23 WBSourceNameType
, @Parm24 WBSourceNameType
, @Parm25 WBSourceNameType
, @Parm26 WBSourceNameType
, @Parm27 WBSourceNameType
, @Parm28 WBSourceNameType
, @Parm29 WBSourceNameType
, @Parm30 WBSourceNameType
, @Parm31 WBSourceNameType
, @Parm32 WBSourceNameType
, @Parm33 WBSourceNameType
, @Parm34 WBSourceNameType
, @Parm35 WBSourceNameType
, @Parm36 WBSourceNameType
, @Parm37 WBSourceNameType
, @Parm38 WBSourceNameType
, @Parm39 WBSourceNameType
, @Parm40 WBSourceNameType
, @Parm41 WBSourceNameType
, @Parm42 WBSourceNameType
, @Parm43 WBSourceNameType
, @Parm44 WBSourceNameType
, @Parm45 WBSourceNameType
, @Parm46 WBSourceNameType
, @Parm47 WBSourceNameType
, @Parm48 WBSourceNameType
, @Parm49 WBSourceNameType
, @Parm50 WBSourceNameType
) AS
DECLARE
@RowPointer RowPointer
, @Whse WhseType
, @TmpAmount AmountType
, @StartWhse WhseType
, @EndWhse WhseType
, @StartItem ItemType
, @EndItem ItemType
, @StartLoc LocType
, @EndLoc LocType
DECLARE @ttItemloc TABLE (
RowPointer uniqueidentifier
, whse nvarchar(4)
, item nvarchar(30)
, loc nvarchar(15)
, amount decimal(20,8)
, processed tinyint
)
SET @StartWhse = ISNULL(@Parm1, dbo.LowString('WhseType'))
SET @EndWhse = ISNULL(@Parm1, dbo.HighString('WhseType'))
SET @StartItem = ISNULL(@Parm2, dbo.LowString('ItemType'))
SET @EndItem = ISNULL(@Parm2, dbo.HighString('ItemType'))
SET @StartLoc = ISNULL(@Parm3, dbo.LowString('LocType'))
SET @EndLoc = ISNULL(@Parm3, dbo.HighString('LocType'))
INSERT INTO @ttItemloc
SELECT RowPointer, whse, item, loc, 0, 0
FROM itemloc
WHERE whse BETWEEN @StartWhse AND @EndWhse
AND item BETWEEN @StartItem AND @EndItem
AND loc BETWEEN @StartLoc AND @EndLoc
WHILE EXISTS (SELECT TOP 1 1 FROM @ttItemloc WHERE processed = 0)
BEGIN
SELECT TOP 1 @RowPointer = RowPointer
FROM @TTItemloc
WHERE processed = 0
SET @TmpAmount = 0
EXEC SSSWBCanInvValSubItemlocSp @RowPointer, @TmpAmount OUTPUT
UPDATE @ttItemloc
SET amount = @TmpAmount
, processed = 1
WHERE RowPointer = @RowPointer
END
INSERT INTO #tt_drill_results(
CHAR01, CHAR02, CHAR03, DECI01, amount, RowPointer
)
SELECT whse, item, loc, amount, amount, RowPointer
FROM @ttItemloc
RETURN 0
相关主题