设置基于存储过程的次级向下钻取

次级向下钻取在从小计数据计算关键编号且需要访问此小计明细的情况下非常有用。可使用父级向下钻取的输出列属性名称作为次级向下钻取的输入参数。

预配置存货值关键编号是基于存储过程的关键编号的良好次级详查示例。此关键编号显示您的整个存货值,按存货详查至小计。它进一步详查至物料合计或按仓库详查至货位。

要将新详查作为次级详查关联:

  1. 创建详查。
  2. 或者,使用 @Parms 参数可在您的详查中接受筛选器。

    例如,存货值明细详查 (SSSWBCanInvValDtlSp) 接受 Whse in @Parm1, Item in @Parm2, and Location in @Parm3。如果它经过编码将这些值用为筛选器使用(如提供),或忽略它们(如未提供)。

  3. 针对您希望如何在存储过程接受参数的顺序指定来源参数。

    当一个详查调用另一个详查时,次级详查自动按列表头名称从调用详查拉出这些值。例如,物料存货值明细详查具有一个名为列标题的物料。当它调用存货值明细次级详查时,此物料值被传递到 @Parm2 中的存货值明细程序。

  4. 启动详查设置表单。
  5. 导航至顶级详查。
  6. 次级详查选项卡上,指定新详查并为其指定说明。
  7. 保存记录。

例如:

一级详查程序:

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
相关主题