SAP Business One PostTransactionNotice: Automatic Audit After Each Transaction - Featured Image

Publications

SAP Business One PostTransactionNotice: Automatic Audit After Each Transaction

Hector Pincheira

Hector Pincheira

CIO | CTO
Digital Strategy & Technology Innovation

items

A user voids an invoice at 11:47 p.m. The next morning, the customer's balance has changed and nobody knows who did it, when, or why. In many companies running SAP Business One, this scene isn't a hypothetical: it's Monday. The SAP Business One PostTransactionNotice procedure exists precisely so that the uncomfortable question —»who touched this?»— always has a traceable, automatic, forget-proof answer.

In an earlier article we worked with SP_TransactionNotification, the gatekeeper that validates before confirming an operation. Today we go to the other side of the clock. This sibling procedure fires after the transaction is already committed in the database. So it isn't there to block, but to record, audit and automate reactions. It's the difference between a doorman and a notary: one decides who gets in; the other leaves a record of everything that happened.

SAP Business One PostTransactionNotice - database infrastructure recording transactions
Every committed transaction leaves a trace; the challenge is capturing it automatically.

What SAP Business One PostTransactionNotice is and why you need it

The procedure SBO_SP_PostTransactionNotice is a stored procedure that SAP Business One runs automatically every time a transaction is committed to the database. As a result, it receives complete information about That object was affected (an invoice, an order, a journal entry) and That type of action occurred: add, update, delete, cancel or close.

The strategic difference with its sibling is key. If SP_TransactionNotification returns an error, the operation is rolled back and the user sees a message. By contrast, when SBO_SP_PostTransactionNotice returns an error, the transaction has already happened: the engine merely writes that error to the SAP logs, without alerting the user. This procedure must therefore never be used to validate; its territory is auditing, logging and silent automation.

Why does this matter at the business level? Because most companies discover they need to know «who did what» on the very day it is already too late. An automatic record of sensitive changes —cancellations, price changes, document closures— turns a hallway argument into an objective fact. Control stops depending on people's memory and starts living in the database.

Real cases where it makes the difference

For example, imagine you want a log of every cancelled invoice, with the user and the exact time. Or you need to feed your own table every time a sales order is closed, so you can measure cycle times. Both scenarios share a pattern: reacting to an accomplished fact without interfering with the operation. That is exactly what this procedure is for.

Prerequisites before starting

Before writing a single line, it pays to have the ground prepared. First, you need access to the database server (SQL Server or SAP HANA) where your SAP Business One company lives, with permissions to alter stored procedures. It is also essential to work first in a testdatabase, never straight into production.

The concrete requirements are these: basic SQL knowledge, identifying the ObjectType of the document you want to audit (for example, 13 for A/R Invoices, 17 for Sales Orders), and a table of your own —ideally a User-Defined Table (UDT)— to hold the record. For the first example, though, we will use a simple log table you can create yourself.

SAP Business One PostTransactionNotice - SQL code of a stored procedure
The procedure lives inside your database and runs with no human intervention.

Step-by-step tutorial: set up your first PostTransactionNotice

Next we will build an automatic log of cancelled invoices. The goal is simple but powerful: every time someone cancels an A/R invoice, the system leaves a record on its own. Follow these steps in order.

Step 1. Create the log table where the record will be stored. Step 2. Locate and edit the procedure SBO_SP_PostTransactionNotice. Step 3. Insert your logic inside the reserved block. Step 4. Test with a real transaction in your test environment. Let's go through each one with the matching code.

Step 1: create the log table

First, we define a simple table that will store the affected object, the document key, the user and the date. As always, we provide both versions depending on your database engine.

SQL Server

-- Log table (SQL Server)
CREATE TABLE [dbo].[Z_BitacoraAcciones] (
    Id            INT IDENTITY(1,1) PRIMARY KEY,
    ObjectType    NVARCHAR(30),
    TransType     NCHAR(1),
    DocKey        NVARCHAR(255),
    Usuario       NVARCHAR(50),
    FechaHora     DATETIME DEFAULT GETDATE()
);

SAP HANA

-- Log table (SAP HANA)
CREATE COLUMN TABLE "Z_BitacoraAcciones" (
    "Id"         BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    "ObjectType" NVARCHAR(30),
    "TransType"  NCHAR(1),
    "DocKey"     NVARCHAR(255),
    "Usuario"    NVARCHAR(50),
    "FechaHora"  TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Steps 2 and 3: edit the procedure and insert the logic

Now comes the heart of the tutorial. The procedure receives five parameters: the object type, the transaction type, how many columns make up the key, the list of key columns and the list of values. For example, when an invoice is cancelled (ObjectType 13, TransType ‘C’), we capture the record. Note the syntax differences between engines.

SQL Server

ALTER PROC [dbo].[SBO_SP_PostTransactionNotice]
    @object_type              NVARCHAR(30),
    @transaction_type         NCHAR(1),
    @num_of_cols_in_key       INT,
    @list_of_key_cols_tab_del NVARCHAR(255),
    @list_of_cols_val_tab_del NVARCHAR(255)
AS
BEGIN
    DECLARE @error INT
    DECLARE @error_message NVARCHAR(200)
    SELECT @error = 0, @error_message = N'Ok'
    -- Log A/R Invoice cancellations (ObjectType 13, Cancel)
    IF @object_type = N'13' AND @transaction_type = N'C'
    BEGIN
        INSERT INTO [dbo].[Z_BitacoraAcciones]
            (ObjectType, TransType, DocKey, Usuario, FechaHora)
        VALUES
            (@object_type, @transaction_type,
             @list_of_cols_val_tab_del, USER_NAME(), GETDATE())
    END
    SELECT @error, @error_message
END

SAP HANA

CREATE PROCEDURE SBO_SP_PostTransactionNotice(
    IN object_type              NVARCHAR(30),
    IN transaction_type         NCHAR(1),
    IN num_of_cols_in_key       INT,
    IN list_of_key_cols_tab_del NVARCHAR(255),
    IN list_of_cols_val_tab_del NVARCHAR(255),
    OUT error         INT,
    OUT error_message NVARCHAR(200) )
LANGUAGE SQLSCRIPT AS
BEGIN
    error := 0;
    error_message := N'Ok';
    -- Log A/R Invoice cancellations (ObjectType 13, Cancel)
    IF :object_type = N'13' AND :transaction_type = N'C' THEN
        INSERT INTO "Z_BitacoraAcciones"
            ("ObjectType", "TransType", "DocKey", "Usuario", "FechaHora")
        VALUES
            (:object_type, :transaction_type,
             :list_of_cols_val_tab_del, CURRENT_USER, CURRENT_TIMESTAMP);
    END IF;
END;

Look closely at the details that change between engines: HANA uses :parametro with a colon, requires double quotes around object names and closes the conditional with END IF. Furthermore, GETDATE() becomes CURRENT_TIMESTAMP and USER_NAME() at CURRENT_USER. These nuances are the number one cause of errors when migrating code between platforms.

Step 4: verify that your log works

After cancelling a test invoice, run a verification query to confirm the record was saved. This query also works as a daily audit report. Below, the dual version showing the actions from the last seven days.

SQL Server

SELECT TOP 100
    Id, ObjectType, TransType, DocKey,
    ISNULL(Usuario, N'Unknown') AS Usuario,
    FechaHora
FROM [dbo].[Z_BitacoraAcciones]
WHERE DATEDIFF(DAY, FechaHora, GETDATE()) <= 7
ORDER BY FechaHora DESC;

SAP HANA

SELECT
    "Id", "ObjectType", "TransType", "DocKey",
    IFNULL("Usuario", N'Unknown') AS "Usuario",
    "FechaHora"
FROM "Z_BitacoraAcciones"
WHERE DAYS_BETWEEN("FechaHora", CURRENT_DATE) <= 7
ORDER BY "FechaHora" DESC
LIMIT 100;
SAP Business One PostTransactionNotice - audit report with log data
The log turns invisible changes into an objective, queryable report.

Advanced variations and use cases

Once you master the base pattern, the possibilities multiply. For example, you can record not only cancellations but also document updates using @transaction_type = N'U'. That gives you a history of who edited each sales order after it was created.

Another frequent case is feeding a KPI dashboard. Every time an order is closed (TransType = 'L'), you can insert the timestamp into a table of your own and measure the real cycle time between creation and closing. Some companies also use it to trigger lightweight integrations: dropping a row into a staging table that an external process later reads to sync with another system. That said, there is a golden rule worth remembering, and we will get to it right away.

Best practices and common mistakes

The first principle is sacred: never put heavy logic here. Because this procedure runs on every committed transaction, an expensive Join or a badly written cursor degrades the performance of the whole system. Keep the code light, conditional and direct. Always filter by @object_type at the very start so you exit fast when it does not apply.

Second, never use this procedure to validate or to try to undo something: the transaction has already happened and any error will only reach the logs. Also avoid modifying SAP's own system tables; always work with your Z_ tables or UDTs. As a result, your customization will survive version upgrades without surprises.

A common mistake is forgetting the final statement. In SQL Server the procedure must end with SELECT @error, @error_message; in HANA you must assign the OUTparameters. If you skip this, SAP Business One can behave unexpectedly. Plenty of consultants lose hours debugging something that is solved by returning the output values correctly.

Official SAP Resources

To go deeper, check the official documentation and the community. First, the SAP Help Portal for SAP Business One describes the database architecture and the ObjectTypes. The SAP Community for Business One also gathers real examples of both procedures, for SQL Server as well as the SAP HANA version.

Conclusion: from «I don't know who did it» to an objective fact

The procedure SAP Business One PostTransactionNotice is one of those silent pieces that separate a company that reacts from one that controls. It does not block, it does not bother the user and it does not ask permission: it simply leaves a record of what matters, automatically and forever. It turns hallway questions into queryable data and defensible decisions.

Now it's your turn. Identify the first critical process that has no log today —cancellations, price changes, closures— and apply the pattern from this tutorial in your test environment. If you want to take your SAP Business One from «a system that records data» to «a system that controls itself», this is the best place to start. What will be the first action you audit in your company?

Most Read

QlikSense Hierarchy: parent-child chart of accounts expanded by levels
QlikSense Hierarchy: the Chart of Accounts That Doesn't Add Up
QlikSense Sum TOTAL: share of each family over the total
QlikSense Sum TOTAL: the Percentage That Changes When You Filter
SAP Business One Inventory Revaluation - featured image of the tutorial
SAP Business One Inventory Revaluation: Fix Wrongly Loaded Costs
Empty chamber with wooden benches: the counterweight that required being present to be used
The Veto You Had to Say in Person: Your Decisions With No Counterweight
SAP Business One customizations - featured image of the pre-upgrade audit tutorial
SAP Business One Customizations: Pre-Upgrade Audit
SAP Business One Customer Concentration - featured image of the tutorial
SAP Business One Customer Concentration: Measure Your Risk with SQL

RELATED ARTICLES