Hi Idress,
Compare the base SO quantity must be less than the delivered quantity.
This should work because the DelivrdQty will always be accumulated by SAP every time user draw from this SO.
SELECT TOP 1 @Error = -1, @error_message = 'Line ' + CONVERT(NVARCHAR(10),T0.VisOrder+1) + ' Total invoice qty exceeds base SO. ' FROM INV1 T0 JOIN RDR1 T1 ON T0.BaseType = T1.ObjType AND T0.BaseEntry = T1.DocEntry AND T0.BaseLine= T1.LineNum WHERE T0.DocEntry = @list_of_cols_val_tab_del AND T1.Quantity<T1.DelivrdQty SELECT @error, @error_message
Regards
Edy