Query to block posting an Invoice entry with quantity more than the quantity on the Sales Order

28/03/2022 smart village SAP

When posting an A/R invoice, Users may want to an invoice with more quantity than the quantity on the Sales Order. To prevent this, use the query below to block posting the entry. The system will generate an error message to warn the user.

Follow the path to post the query:

Login to Microsoft SQL Server Management Studio

  1. Expand Databases.
  2. Expand Your Database in this case (SVTL2022).
  3. Expand Programmability.
  4. Expand Stored Procedures.
  5. Scroll down to dbo.SBO_SP_TransactionNotification.

Right Click on dbo.SBO_SP_TransactionNotification

6. Click Modify

7. Paste Query in the section indicated above “Insert your query here”

8. Click Execute

 

IF @transaction_type IN (N’A’, N’U’) AND (@Object_type = N’13’)

BEGIN

Declare @invoice int

SELECT @invoice = (LineNum + 1) FROM INV1

WHERE INV1.DocEntry = @list_of_cols_val_tab_del AND

((Quantity > BaseOpnQty) and (inv1.ItemCode != ‘LMF100451’)) AND

((Quantity > BaseOpnQty) and (inv1.ItemCode != ‘LMF100451’))

ORDER BY LineNum ASC

IF (not ISNULL(@invoice, 0) = 0)

BEGIN

SET @error = 10

SET @error_message = N’Invoiced quantity cannot exceed Sales order quantity ‘ + CONVERT(nvarchar(4), @invoice) + N’ !’

End

END