2

我的存储过程 SAP B1 有问题。

我在这里要做的是存储数量的总和,按制造订单分组并将其插入临时表。然后使用 while 循环遍历每个 ID 以与用户表 [@FGTRACKING] 进行比较,并阻止 [@FGTracking] 中的 temp.quantity > sum(quantity)。

但是这不起作用,事务仍然通过了存储过程块。我怀疑我的语法有问题。

IF @transaction_type IN ('A') AND @object_type = '67'
    BEGIN
    declare @top as int
    declare @temp table (id int,quantity int NOT NULL, monum int NOT NULL)
    insert into @temp (id, quantity,monum)
    select row_number() over (order by (select NULL)), sum(quantity) as quantity, u_shipment_line as monum
    from wtr1 t1
    where t1.docentry = @list_of_cols_val_tab_del
    group by u_shipment_line
    set @top = 1
    WHILE @top <= (select count(monum) from @temp)
    BEGIN
    IF EXISTS (select t100.monum from @temp t100 
    where t100.quantity > (select sum(t111.u_transfer) 
    from [@FGTRACKING] t111 where t111.u_mo_num = t100.monum 
    group by t111.u_mo_num) and t100.id = @top)
    BEGIN
    SELECT @Error = 666, @error_message = 'Over-transfer'
    END
    ELSE
    set @top = @top + 1
    END
    END
4

1 回答 1

0

看起来您只是在没有遇到错误条件时才增加迭代器(@top),所以如果您的错误条件触发,您就会陷入无限循环。

摆脱您的“else”并始终增加@top,或者在遇到错误条件时退出您的while循环。

...
ELSE  -- Get rid of this else
set @top = @top + 1
...
于 2016-11-29T18:35:17.137 回答