SAP Business One Inventory Audit: Reconcile Stock and Accounting with SQL

Publications

SAP Business One Inventory Audit: Reconcile Stock and Accounting with SQL

Hector Pincheira

Hector Pincheira

CIO | CTO
Digital Strategy & Technology Innovation

items

The SAP Business One inventory audit It's that awkward conversation that repeats every month-end: the warehouse manager swears there is 480 million in inventory, the accountant shows a balance of 496 million in the merchandise account, and no one can explain the 16 million difference. Consequently, the closing is delayed, the auditor raises a finding, and management begins to distrust the entire ERP over a discrepancy that is almost never the system's fault.

After several closing processes supporting administration and finance teams, I learned something that changes the approach: the discrepancy is not solved by looking at the inventory. It is solved by understanding that SAP Business One maintains two parallel records of the same value, and that there is a limited handful of reasons why those two records can diverge. Therefore, the job is not to count boxes again, but to identify which of those reasons was triggered and in which document.

In this tutorial, you will build a reconciliation dashboard with SQL that shows you, on a single screen, the logistic value, the accounting balance, and the variance by item group. In addition, you will have the forensic queries to find the exact journal entry that broke the balance. All with versions for SQL Server and SAP HANA.

SAP Business One inventory posting - reconciliation of financial reports and general ledger balances
Inventory mismatch is almost never an ERP error: it is a trail of decisions recorded outside the logistics flow.

Why you need to master inventory reconciliation

When you buy an ERP, you buy the promise of a single version of the truth. However, inventory is the company's only asset that is recorded twice by design: once in the logistics module, with quantities and values by item and warehouse, and again in accounting, as a balance of one or more inventory accounts. SAP Business One automatically synchronizes both records every time an inventory document generates its journal entry. In this way, the system keeps things reconciled without human intervention.

The problem arises when someone intervenes in the same way. For example, an accountant who adjusts the inventory account with a manual entry to «balance the sheet» has just broken the synchronization: they moved the accounting without moving the stock. Consequently, the discrepancy not only persists, but becomes harder to track because there are now two overlapping errors.

Also, there is a hidden cost. An inaccurate inventory contaminates the cost of goods sold, and a contaminated cost of goods sold distorts the margin you report to management. In other words: you are not fixing an accounting issue, you are protecting the quality of the information used to make pricing decisions.

Prerequisites before writing the first query

Here is what you need to have sorted out before you start. None of these points are optional.

  • Read permissions on the production database, or access to the Query Manager in Tools > Queries > Query Builder.
  • Find out if your company uses perpetual inventory (perpetual inventory). Verify it in Administration > System Initialization > Company Details > Basic Initialization tab. If the checkbox is not selected, SAP Business One does not generate automatic inventory journal entries and this reconciliation does not apply.
  • The list of your inventory accounts, as they are configured in Management > Definitions > Financials > G/O Account Determination > Inventory tab, or in the definition of each group of articles.
  • The account determination level what your company uses: by warehouse, by item group, or by item. This defines how you will group the comparison.
  • A defined cutoff date, normally the last day of the accounting month you are closing.

An important notice: always run these queries on a copy or during low-load hours. These are aggregation queries on large historical tables and may compete for resources with the operation.

Step 1: start with the native report, not the SQL

Before writing a line of code, use the tool that SAP already gave you. Go to Inventory > Inventory reports > Inventory audit report. This report reconstructs, movement by movement, how the value of your inventory was formed and displays in parallel the accounting entry generated by each one.

Run it filtering by inventory account and by the range of the period you are closing. Afterward, compare the total with the balance of the same account on the trial balance. If both match, your problem is not a reconciliation issue: it is one of interpretation, and someone is probably looking at a stock report at list price instead of cost.

However, this report has a serious practical limit: it doesn't tell you why There is a difference when there is one. It just shows you two different columns. That's why SQL is necessary from here on.

Step 2: Identify your inventory accounts

All reconciliation depends on working with the correct list of accounts. Consequently, this query is the mandatory starting point. Run it and compare the result with the account determination screen.

SQL Server

-- Candidate inventory accounts in the chart of accounts
SELECT
    T0.AcctCode                AS Account,
    T0.FormatCode              AS FormatCode,
    T0.AcctName                AS AccountName,
    T0.CurrTotal               AS CurrentBalance
FROM OACT T0
WHERE T0.Postable = 'N0'
  AND (T0.AcctName LIKE '%xisten%'
    OR T0.AcctName LIKE '%nventar%'
    OR T0.AcctName LIKE '%ercader%')
ORDER BY T0.FormatCode;

SAP HANA

-- Candidate inventory accounts in the chart of accounts
SELECT
    T0."AcctCode"              AS "Account",
    T0."FormatCode"            AS "FormattedCode",
    T0."AcctName"              AS "AccountName",
    T0."CurrTotal"             AS "CurrentBalance"
FROM OACT T0
WHERE T0."Postable" = 'N0'
  AND (T0."AcctName" LIKE '%xisten%'
    OR T0."AcctName" LIKE '%nventar%'
    OR T0."AcctName" LIKE '%ercader%')
ORDER BY T0."FormatCode";

A clarification regarding the field PostableIn SAP Business One, indicate whether the account allows manual journal entries. Adjust the value according to your version if the filter returns no results; alternatively, remove that condition and review the complete list. The essential thing is to keep the internal account codes, which usually have the format _SYS00000000123. Those are the codes you will use in the following queries.

Step 3: Calculate the logistic value of the inventory

The first side of the equation comes from OINM, the inventory transaction ledger. Each row represents an inbound or outbound movement, with its quantity and valuation. Therefore, the running total of TransValue Up to a date is equivalent to the inventory value on that date.

SQL Server

-- Inventory value according to the logistics module as of a cutoff date
DECLARE @CutoffDate DATE = '2026-08-31';
SELECT
    T2.ItemGroupName                          AS ItemGroup,
    T1.Warehouse                           AS Warehouse,
    SUM(T1.InQty - T1.OutQty)              AS StockQuantity,
    SUM(T1.TransValue)                     AS LogisticsValue
FROM OINM T1
INNER JOIN OITM T0 ON T0.ItemCode   = T1.ItemCode
INNER JOIN OITB T2 ON T2.ItmsGrpCod = T0.ItmsGrpCod
WHERE T1.DocDate <= @Cut-offDate
  AND T0.InvntItem = 'Y'
GROUP BY T2.ItmsGrpName, T1.Warehouse
HAVING SUM(T1.TransValue) <> 0
ORDER BY 1, 2;

SAP HANA

-- Inventory value according to the logistics module as of a cutoff date
SELECT
    T2."ItmsGrpNam"                        AS "ItemGroup",
    T1."Warehouse"                         AS "Warehouse",
    SUM(T1."InQty" - T1."OutQty")          AS "StockQuantity",
    SUM(T1."TransValue")                   AS "LogisticsValue"
FROM OINM T1
INNER JOIN OITM T0 ON T0."ItemCode"   = T1."ItemCode"
INNER JOIN OITB T2 ON T2."ItmsGrpCod" = T0."ItmsGrpCod"
WHERE T1."DocDate" <= '2026-08-31'
  AND T0."InvntItem" = 'Y'
GROUP BY T2."ItmsGrpNam", T1."Warehouse"
HAVING SUM(T1."TransValue") <> 0
ORDER BY 1, 2;

Check out the filter InvntItem = 'Y'. Exclude items that do not manage stock, such as services or sell-only items. Without that filter, you drag along noise that never had a matching accounting inventory entry. In addition, the Having delete the group and warehouse combinations that resulted in zero, which are usually the majority in databases with a long history.

Step 4: calculate the book balance of the same inventory

The second side comes from JDT1, the details of all accounting entries. Here you add debit minus credit for the inventory accounts up to the same cutoff date. Consequently, you get the exact number that appears on your balance sheet.

SQL Server

-- Book balance of inventory accounts as of the cutoff date
DECLARE @FechaCorte DATE = '2026-08-31';
SELECT
    T0.Account                   AS Account,
    T1.AcctName                  AS AccountName,
    SUM(T0.Debit)                AS TotalDebit,
    SUM(T0.Credit)               AS TotalCredit,
    SUM(T0.Debit - T0.Credit)    AS BookBalance
FROM JDT1 T0
INNER JOIN OACT T1 ON T1.AcctCode = T0.Account
WHERE T0.RefDate <= @FechaCorte
  AND T0.Account IN ('_SYS00000000123', '_SYS00000000124')  -- replace with your accounts
GROUP BY T0.Account, T1.AcctName
ORDER BY 1;

SAP HANA

-- Book balance of inventory accounts as of the cutoff date
SELECT
    T0."Account"                     AS "Account",
    T1."AcctName"                    AS "Account Name",
    SUM(T0."Debit")                  AS "Total Debit",
    SUM(T0."Credit")                 AS "Total Credit",
    SUM(T0."Debit" - T0."Credit")    AS "Book Balance"
FROM JDT1 T0
INNER JOIN OACT T1 ON T1."AcctCode" = T0."Account"
WHERE T0."RefDate" <= '2026-08-31'
  AND T0."Account" IN ('_SYS00000000123', '_SYS00000000124')  -- replace with your accounts
GROUP BY T0."Account", T1."AcctName"
ORDER BY 1;

A detail that costs dearly if overlooked: use Reference Date and why not Creation Date. The posting date is what determines the period, whereas the creation date merely records when someone entered the document. For example, an entry created on September 5th with a posting date of August 31st belongs to August, and your reconciliation must reflect it as such.

Step 5: The reconciliation dashboard in a single query

Now we join both sides. Since the link between the article group and the general ledger account depends on your specific configuration, the query includes an explicit mapping table that you only need to fill out once. This way the report remains documented and auditable, instead of relying on an implicit relationship that no one remembers.

SQL Server

-- Reconciliation Report: Logistics vs. Accounting
DECLARE @CutoffDate DATE = '2026-08-31';
;WITH Mapping AS (
    SELECT * FROM (VALUES
        ('Raw Materials',       '_SYS00000000123'),
        ('Finished Goods',  '_SYS00000000124'),
        ('Spare Parts',           '_SYS00000000125')
    ) AS M (ItemGroup, Account)
),
Logistics AS (
    SELECT T2.ItmsGrpNam AS ItemGroup, SUM(T1.TransValue) AS LogisticsValue
    FROM OINM T1
    INNER JOIN OITM T0 ON T0.ItemCode   = T1.ItemCode
    INNER JOIN OITB T2 ON T2.ItemGrpCode = T0.ItemGrpCode
    WHERE T1.DocDate <= @CutoffDate AND T0.InvntItem = 'Y'
    GROUP BY T2.ItemGrpName
),
Accounting AS (
    SELECT T0.Account AS Account, SUM(T0.Debit - T0.Credit) AS AccountingBalance
    FROM JDT1 T0
    WHERE T0.RefDate <= @CutOffDate
    GROUP BY T0.Account
)
SELECT
    M.ItemGroup,
    M.Account,
    ISNULL(L.LogisticsValue, 0)                                AS LogisticsValue,
    ISNULL(C.AccountingBalance, 0)                                 AS AccountingBalance,
    ISNULL(L.LogisticsValue, 0) - ISNULL(C.AccountingBalance, 0)   AS Difference
FROM Mapping M
LEFT JOIN Logistics L ON L.ItemGroup = M.ItemGroup
LEFT JOIN Accounting C ON C.Account         = M.Account
ORDER BY ABS(ISNULL(L.LogisticsValue, 0) - ISNULL(C.AccountingBalance, 0)) DESC;

Dónde ejecutar este query. Úsalo en SQL Server Management Studio o en HANA Studio. El Generador de consultas de SAP Business One no siempre digiere las expresiones de tabla común (WITH), así que si necesitas el resultado dentro de B1, guarda la consulta como vista y llama a la vista desde el Generador.

SAP HANA

-- Reconciliation Table: Logistics vs. Accounting
WITH "Mapping" AS (
    SELECT 'Raw Materials'      AS "ItemGroup", '_SYS00000000123' AS "Account" FROM DUMMY
    UNION ALL
    SELECT 'Finished Goods' AS "ItemGroup", '_SYS00000000124' AS "Account" FROM DUMMY
    UNION ALL
    SELECT 'Spare Parts'          AS "ItemGroup", '_SYS00000000125' AS "Account" FROM DUMMY
),
"Logistics" AS (
    SELECT T2."ItmsGrpNam" AS "ItemGroup", SUM(T1."TransValue") AS "LogisticsValue"
    FROM OINM T1
    INNER JOIN OITM T0 ON T0."ItemCode"   = T1."ItemCode"
    INNER JOIN OITB T2 ON T2."ItmsGrpCod" = T0."ItmsGrpCod"
    WHERE T1."DocDate" <= '2026-08-31' AND T0."InvntItem" = 'Y'
    GROUP BY T2."ItemsGroupName"
),
"Accounting" AS (
    SELECT T0."Account" AS "Account", SUM(T0."Debit" - T0."Credit") AS "AccountingBalance"
    FROM JDT1 T0
    WHERE T0."RefDate" <= '2026-08-31'
    GROUP BY T0."Account"
)
SELECT
    M."ItemGroup",
    M."Account",
    IFNULL(L."InventoryValue", 0)                                     AS "InventoryValue",
    IFNULL(C."AccountingBalance", 0)                                      AS "AccountingBalance",
    IFNULL(L."LogisticsValue", 0) - IFNULL(C."AccountingBalance", 0)      AS "Difference"
FROM "Mapping" M
LEFT JOIN "Logistics" L ON L."ItemGroup" = M."ItemGroup"
LEFT JOIN "Accounting"  C ON C."Account"         = M."Account"
ORDER BY ABS(IFNULL(L."LogisticsValue", 0) - IFNULL(C."AccountingBalance", 0)) DESC;

The result sorts the groups by magnitude of difference, from largest to smallest. That way, you tackle the areas where the money is first. In most of the companies I've seen, a single line accounts for more than 80% of the total discrepancy.

SAP Business One inventory posting - warehouse with inventory valued by warehouse
Physical inventory is only half the problem: the other half lives in the chart of accounts.

Step 6: the forensic query that finds the culprit

You already know how much and where. Now you need to know who and when. The number one cause of discrepancies, by far over all the others, is the manual journal entry posted directly against an inventory account. That entry moves the accounting without moving a single gram of stock. Therefore, this query usually solves the case on the first try.

SQL Server

-- Manual entries against inventory accounts
SELECT
    T1.TransId        AS EntryNo,
    T1.RefDate        AS Date,
    T0.Account        AS Account,
    T2.AcctName       AS AccountName,
    T0.Debit          AS Debit,
    T0.Credit         AS Credit,
    T0.LineMemo       AS Memo,
    T3.U_NAME         AS User
FROM JDT1 T0
INNER JOIN OJDT T1 ON T1.TransId  = T0.TransId
INNER JOIN OACT T2 ON T2.AcctCode = T0.Account
LEFT  JOIN OUSR T3 ON T3.USERID   = T1.UserSign
WHERE T1.TransType = 30                    -- 30 = manual entry
  AND T0.RefDate BETWEEN '2026-01-01' AND '2026-08-31'
  AND T0.Account IN ('_SYS00000000123', '_SYS00000000124')
ORDER BY T0.RefDate DESC;

SAP HANA

-- Manual journal entries vs inventory accounts
SELECT
    T1."TransId"      AS "JE_Num",
    T1."RefDate"      AS "Date",
    T0."Account"      AS "Account",
    T2."AcctName"     AS "AccountName",
    T0."Debit"        AS "Debit",
    T0."Credit"       AS "Credit",
    T0."LineMemo"     AS "Details",
    T3."U_NAME"       AS "User"
FROM JDT1 T0
INNER JOIN OJDT T1 ON T1."TransId"  = T0."TransId"
INNER JOIN OACT T2 ON T2."AcctCode" = T0."Account"
LEFT  JOIN OUSR T3 ON T3."USERID"   = T1."UserSign"
WHERE T1."TransType" = 30                  -- 30 = manual journal entry
  AND T0."RefDate" BETWEEN '2026-01-01' AND '2026-08-31'
  AND T0."Account" IN ('_SYS00000000123', '_SYS00000000124')
ORDER BY T0."RefDate" DESC;

If this query returns rows, you already have your explanation and also your pending conversation with the accounting team. Each of those lines is an adjustment that was made outside the process, and the sum of their balances should be very close to the difference you calculated in the previous step.

Step 7: Discrepancy by document, when the manual one does not appear

Sometimes the previous query returns nothing and the discrepancy persists. In that scenario, the problem is within the normal flow: a document that moved inventory and generated an entry for a different amount. This query compares both sides document by document.

SQL Server

-- Comparison of logistics transaction vs. journal entry, by document
;WITH MovLog AS (
    SELECT T0.TransType, T0.BASE_REF, SUM(T0.TransValue) AS LogisticsValue
    FROM OINM T0
    WHERE T0.DocDate BETWEEN '2026-08-01' AND '2026-08-31'
    GROUP BY T0.TransType, T0.BASE_REF
),
MovCon AS (
    SELECT T0.TransType, T0.BaseRef,
           SUM(T0.Debit - T0.Credit) AS AccountingValue
    FROM JDT1 T0
    WHERE T0.RefDate BETWEEN '2026-08-01' AND '2026-08-31'
      AND T0.Account IN ('_SYS00000000123', '_SYS00000000124')
    GROUP BY T0.TransType, T0.BaseRef
)
SELECT
    L.TransType                                            AS DocumentType,
    L.BASE_REF                                             AS DocumentNumber,
    L.LogisticalValue,
    ISNULL(C.BookValue, 0)                             AS BookValue,
    L.LogisticsValue - ISNULL(C.BookValue, 0)          AS Difference
FROM MovLog L
LEFT JOIN MovCon C ON C.TransType = L.TransType AND C.BaseRef = L.BASE_REF
WHERE ABS(L.LogisticalValue - ISNULL(C.BookValue, 0)) > 1
ORDER BY ABS(L.LogisticalValue - ISNULL(C.BookValue, 0)) DESC;

SAP HANA

-- Comparison of logistics transaction vs. journal entry, by document
WITH "MovLog" AS (
    SELECT T0."TransType", T0."BASE_REF", SUM(T0."TransValue") AS "LogisticsValue"
    FROM OINM T0
    WHERE T0."DocDate" BETWEEN '2026-08-01' AND '2026-08-31'
    GROUP BY T0."TransType", T0."BASE_REF"
),
"MovCon" AS (
    SELECT T0."TransType", T0."BaseRef",
           SUM(T0."Debit" - T0."Credit") AS "BookValue"
    FROM JDT1 T0
    WHERE T0."RefDate" BETWEEN '2026-08-01' AND '2026-08-31'
      AND T0."Account" IN ('_SYS00000000123', '_SYS00000000124')
    GROUP BY T0."TransType", T0."BaseRef"
)
SELECT
    L."TransType"                                                AS "Document Type",
    L."BASE_REF"                                                 AS "Document Number",
    L."LogisticsValue",
    IFNULL(C."BookValue", 0)                                 AS "BookValue",
    L."LogisticsValue" - IFNULL(C."BookValue", 0)            AS "Difference"
FROM "MovLog" L
LEFT JOIN "MovCon" C ON C."TransType" = L."TransType" AND C."BaseRef" = L."BASE_REF"
WHERE ABS(L."LogisticalValue" - IFNULL(C."BookValue", 0)) > 1
ORDER BY ABS(L."LogisticalValue" - IFNULL(C."BookValue", 0)) DESC;

The 1 monetary unit threshold filters out rounding noise, which always exists and never matters. Adjust it according to the currency and scale of your operation. Furthermore, the field TransType it indicates the type of source document: 20 is goods receipt PO, 15 is delivery, 13 is A/R invoice, 59 is goods receipt, and 60 is goods issue.

Additional variations and use cases

The base dashboard solves the monthly close. However, the same structure enables other worthwhile uses.

  • Reconciliation by warehouse. If your account determination is by warehouse and not by item group, change the group by the Item Group Name a Warehouse and adjust the mapping table. The logic does not change.
  • Automatic variance alert. Embed the query from Step 5 inside an alert in Management > Alerts, scheduled for the 1st of each month. This way, the team finds out about the difference before the auditor discovers it.
  • Historical series of the discrepancy. Run the dashboard for the last twelve closings and graph the difference. If it grows steadily, you have a process problem, not an isolated incident.
  • Post-migration validation. After a data migration or a change in the valuation method, this reconciliation is objective proof that the load remained consistent.
  • Audit preparation. Submit the reconciled dashboard along with the list of manual journal entries. Drastically reduce the time for the external review.

Best practices and common mistakes

Block the inventory accounts for manual entries

This is the highest-impact and most ignored measure. In Finance > Chart of accounts, review each inventory account and restrict who can post directly to it through authorizations. As a result, you root out the main cause of the discrepancy. If the business needs a value adjustment, the correct path is an inventory revaluation, not a manual journal entry.

Do not confuse inventory value with replacement value

A classic mistake in closing meetings: someone brings a valued stock report at list price or last purchase cost and compares it against accounting. Naturally, it doesn't match, because accounting records the actual cost according to the configured valuation method. For example, with moving average price, the unit cost changes with each receipt. Always check the field EvalSystem of the article before discussing figures.

Close the accounting periods

If your periods remain open, any user can post with a retroactive date and throw off a month you had already reconciled. Therefore, closing periods is not bureaucracy: it is the mechanism that freezes your reconciliation work.

Watch out for negative stock

If your company allows negative inventory quantities, valuation becomes unstable and discrepancies appear without an identifiable culprit. Check the configuration in Company details > Basic initialization. In well-managed operations, that box is unchecked.

Consider pending import costs

When working with landed costs, there is a time window between the receipt of the goods and the application of the additional costs. During that window, the inventory is legitimately undervalued. Consequently, document that item as reconciling rather than chasing it as an error.

Document every reconciliation item

Not every difference is an error. Some are temporary and explicable. However, they must be documented, quantified, and have an estimated resolution date. A professional reconciliation is not one without differences, but one where every difference has a name and an owner.

SAP Business One Inventory Posting - Review of Accounting Entries and Reconciling Items
A professional reconciliation is not one that has no differences: it is one where every difference is explained.

Official SAP Resources

For further study, these are the documents you should have on hand.

Conclusion: balancing as a sign of maturity

Inventory reconciliation is one of the best indicators of a company's level of operational discipline. An organization that reconciles effortlessly has respected processes, well-defined permissions, and periods closed on time. An organization that struggles with reconciliation every month actually has a data governance problem disguised as an accounting problem.

Therefore, the question you should take to your next closing meeting is not «how much do we have left to reconcile.» It is «why do we continue to allow it to become unbalanced.» The queries in this tutorial answer the first question in minutes. The second is a management decision, and no ERP can solve that.

Implement the Step 5 dashboard, schedule it as a monthly alert, and save the result. In three months, you will have something you don't have today: objective evidence of whether your inventory process is improving or deteriorating.

Do you want to take this analysis to the next level? In the Strategic Circle, I publish weekly practical SAP Business One tutorials with production-ready queries, report templates, and the architecture decisions behind each implementation. If your role is to make technology deliver results and not just work, that is your place.

Most Read

Ballena jorobada bajo el agua con su aleta pectoral extendida: la esperanza en la tecnología y la biomimética
La ballena que volvió: la esperanza en la tecnología y la que no cabe en un tablero
SAP data in ChatGPT: an open door at the far end of a dark room
The Tab Next Door: The SAP Data in ChatGPT That Nobody Authorized
SAP Business One Purchase Price Variance - featured image of the tutorial
SAP Business One Purchase Price Variance: Detect the Inflation in Your Buying Costs
QlikSense format changeovers: actual minutes against the standard
QlikSense Format Changeovers: the Minutes Nobody Bills
QlikSense buttons and actions: executive dashboard with indicators
QlikSense Buttons and Actions: the Dashboard that Runs the Meeting
SAP Business One Internal Reconciliation - featured image of the tutorial
SAP Business One Internal Reconciliation: Clear False Open Items

RELATED ARTICLES