Block Posting Entry When the Quantity Delivered is More than the Quantity on the Sales Order

27/03/2022 smart village SAP

In SAP Business One, users can post a delivery with more quantity than the sales order allows. To block delivery quantity that exceeds the sales order, add a validation to the SBO_SP_TransactionNotification stored procedure. When a user tries to post an over-delivery, SAP Business One stops the transaction and shows an error message with the line number that needs correcting.

Why block delivery quantity above the sales order?

Over-deliveries cause stock differences, billing disputes and extra returns or credit notes. Customers receive goods they did not order, and your warehouse and finance teams spend time reversing documents. A check at posting time stops the problem at the source.

How to add the query

  1. Log in to Microsoft SQL Server Management Studio.
  2. Expand Databases.
  3. Expand your company database (in this example, SVTL2022).
  4. Expand Programmability.
  5. Expand Stored Procedures.
  6. Scroll down to dbo.SBO_SP_TransactionNotification, right-click it and select Modify.
  7. Paste the query in the section marked “Insert your query here”.
  8. Click Execute to save the procedure.

Tip: Test every change to SBO_SP_TransactionNotification in a test company database first, and keep a copy of the original procedure before you modify it.

Query to block delivery quantity greater than the sales order

IF @transaction_type IN (N'A', N'U') AND (@Object_type = N'15')
BEGIN
    DECLARE @numlinii int

    SELECT @numlinii = (LineNum + 1)
    FROM DLN1
    WHERE DLN1.DocEntry = @list_of_cols_val_tab_del
      AND ((Quantity > BaseOpnQty))
    ORDER BY LineNum ASC

    IF (NOT ISNULL(@numlinii, 0) = 0)
    BEGIN
        SET @error = 10
        SET @error_message = N'Delivered quantity cannot exceed Sales order quantity ' + CONVERT(nvarchar(4), @numlinii) + N' !'
    END
END

How the query works

  • It runs when a delivery (object type 15) is added or updated.
  • It compares the quantity on each delivery line (DLN1) with the open quantity left on the base sales order line (BaseOpnQty).
  • If any line is higher, SAP Business One blocks the posting and shows the line number in the error message.

Related SAP Business One queries

You can apply the same approach to other documents. See how to block invoice quantity above the sales order and how to block GRPO quantity above the purchase order.