Balance Sheet in SAP Business One: Build It with SQL Queries - featured image of the tutorial

Publications

Balance Sheet in SAP Business One: Build It with SQL Queries

Hector Pincheira

Hector Pincheira

CIO | CTO
Digital Strategy & Technology Innovation

items

The SAP Business One Balance Sheet is delivered by the system in a couple of clicks, and even so very few managers look at it without a knot in their stomach. The reason is not accounting: it is that nobody knows for certain where each line came from. Therefore, when the auditor asks why the inventory account shows one number and the inventory module shows another, the conversation gets tangled. In this tutorial you will build that balance sheet with SQL, line by line, so you stop trusting the report and start understanding it.

Working the balance sheet from the database changes the game. Besides reproducing the official financial statement, you gain something the standard report does not give you: full traceability from the total down to the journal entry that created it. And with that you can close a month without leaving loose ends.

SAP Business One Balance Sheet - reviewing financial statements
The balance sheet stops being a black box once you can rebuild it line by line.

Why You Need the SAP Business One Balance Sheet in SQL

The standard SAP report works. The problem shows up when you need something outside its mold: comparing two arbitrary cut-off dates, excluding a cost center, showing only the accounts with activity in the period, or cross-checking the ledger balance against the subledger on the same screen. For all of that, the standard generator leaves you halfway.

Below are three situations where the SQL query solves what the interface cannot:

  • Partial closes. You need the balance sheet as of the 15th for a due diligence and the standard report thinks in terms of complete accounting periods.
  • Auditing mismatches. When Assets do not equal Liabilities plus Equity, the report shows you the difference but does not tell you where it was born.
  • Integration with Excel or Power BI. A SQL view feeds a dashboard directly, with no manual export every month.

There is also a less elegant reason. As a consequence of how SAP handles profit and loss accounts, the system calculates the profit for the year on the fly and injects it into equity without leaving a visible trace. If you do not replicate that calculation, your query will never tie out against the official report. This has cost me dearly more than once: two full nights hunting for a phantom journal entry that never existed.

Prerequisites before writing the first query

Before you start, check that you have the following:

  1. Read access to the production database or, better still, to a recent backup copy.
  2. Query Manager permissions in SAP Business One (Tools → Queries → Query Manager).
  3. The chart of accounts configured with the correct level structure in OACT.
  4. Knowing the start date of your fiscal year and the active accounting period.
  5. Identifying whether your installation runs on SQL Server or on SAP HANA.

There are three tables you will use: OACT (chart of accounts), JDT1 (journal entry lines) and OJDT (journal entry header). The whole balance sheet comes from there.

How the SAP Business One Balance Sheet Is Built Step by Step

Step 1: Understand the GroupMask field

In OACT, the field GroupMask classifies each account according to its group in the chart of accounts:

  • 1 = Assets
  • 2 = Liabilities
  • 3 = Equity (Capital and Reserves)
  • 4 = Turnover
  • 5 = Cost of sales
  • 6 = Operating costs
  • 7 = Non-operating income and expenditure
  • 8 = Taxation and extraordinary items

Groups 1, 2 and 3 make up the balance sheet. Groups 4 through 8 make up the profit and loss statement, and their net result accumulates in equity as the profit for the year.

Step 2: Filter only postable accounts

The field Postable is 'Y' on the accounts that accept postings and 'N' on titles and subtitles. If you do not filter by Postable = 'Y', you will duplicate balances, because title accounts accumulate their children.

Step 3: Define the cut-off date

The balance of a balance sheet account is cumulative from the very beginning, not from the start of the year. Therefore, the query adds up every movement in JDT1 with Reference Date less than or equal to your cut-off date, with no start date.

Step 4: Calculate the balance with the correct sign

Assets increase with debits. Liabilities and equity increase with credits. This way, if you always calculate SUM(Debit) - SUM(Credit), assets come out positive and liabilities negative. It is a perfectly valid convention and far easier to audit than flipping signs per group.

Query 1: Balance Sheet Summarized by Group

This first query delivers the balance sheet in its most compressed form: three lines and the reconciliation check.

SQL Server

-- Balance General resumido a una fecha de corte
DECLARE @FechaCorte DATE = '2026-09-30';
SELECT
    CASE A.GroupMask
        WHEN 1 THEN '1. ACTIVO'
        WHEN 2 THEN '2. PASIVO'
        WHEN 3 THEN '3. PATRIMONIO'
    END                                   AS Grupo,
    SUM(ISNULL(J.Debit, 0))               AS TotalDebe,
    SUM(ISNULL(J.Credit, 0))              AS TotalHaber,
    SUM(ISNULL(J.Debit, 0) - ISNULL(J.Credit, 0)) AS Saldo
FROM OACT A
INNER JOIN JDT1 J ON J.Account = A.AcctCode
WHERE A.Postable = 'Y'
  AND A.GroupMask IN (1, 2, 3)
  AND J.RefDate <= @FechaCorte
GROUP BY A.GroupMask
ORDER BY A.GroupMask;

SAP HANA

-- Balance General resumido a una fecha de corte
SELECT
    CASE A."GroupMask"
        WHEN 1 THEN '1. ACTIVO'
        WHEN 2 THEN '2. PASIVO'
        WHEN 3 THEN '3. PATRIMONIO'
    END                                        AS "Grupo",
    SUM(IFNULL(J."Debit", 0))                  AS "TotalDebe",
    SUM(IFNULL(J."Credit", 0))                 AS "TotalHaber",
    SUM(IFNULL(J."Debit", 0) - IFNULL(J."Credit", 0)) AS "Saldo"
FROM OACT A
INNER JOIN JDT1 J ON J."Account" = A."AcctCode"
WHERE A."Postable" = 'Y'
  AND A."GroupMask" IN (1, 2, 3)
  AND J."RefDate" <= TO_DATE('2026-09-30', 'YYYY-MM-DD')
GROUP BY A."GroupMask"
ORDER BY A."GroupMask";

If you add up the three lines of the field Balance, the result should be the profit for the year with the sign reversed. It is not an error: it is exactly the amount SAP transfers to equity.

Query 2: Balance Sheet Detailed by Account

Now we go down to the detail. This query delivers every postable account with its balance as of the cut-off date, ready to paste into Excel and compare against the official report.

SQL Server

-- Balance General detallado por cuenta
DECLARE @FechaCorte DATE = '2026-09-30';
SELECT
    A.AcctCode                            AS Cuenta,
    A.AcctName                            AS Descripcion,
    CASE A.GroupMask
        WHEN 1 THEN 'ACTIVO'
        WHEN 2 THEN 'PASIVO'
        WHEN 3 THEN 'PATRIMONIO'
    END                                   AS Grupo,
    A.Levels                              AS Nivel,
    SUM(ISNULL(J.Debit, 0))               AS Debe,
    SUM(ISNULL(J.Credit, 0))              AS Haber,
    SUM(ISNULL(J.Debit, 0) - ISNULL(J.Credit, 0)) AS Saldo,
    COUNT(J.TransId)                      AS Movimientos
FROM OACT A
LEFT JOIN JDT1 J
       ON J.Account = A.AcctCode
      AND J.RefDate <= @FechaCorte
WHERE A.Postable = 'Y'
  AND A.GroupMask IN (1, 2, 3)
GROUP BY A.AcctCode, A.AcctName, A.GroupMask, A.Levels
HAVING SUM(ISNULL(J.Debit, 0) - ISNULL(J.Credit, 0)) <> 0
ORDER BY A.GroupMask, A.AcctCode;

SAP HANA

-- Balance General detallado por cuenta
SELECT
    A."AcctCode"                               AS "Cuenta",
    A."AcctName"                               AS "Descripcion",
    CASE A."GroupMask"
        WHEN 1 THEN 'ACTIVO'
        WHEN 2 THEN 'PASIVO'
        WHEN 3 THEN 'PATRIMONIO'
    END                                        AS "Grupo",
    A."Levels"                                 AS "Nivel",
    SUM(IFNULL(J."Debit", 0))                  AS "Debe",
    SUM(IFNULL(J."Credit", 0))                 AS "Haber",
    SUM(IFNULL(J."Debit", 0) - IFNULL(J."Credit", 0)) AS "Saldo",
    COUNT(J."TransId")                         AS "Movimientos"
FROM OACT A
LEFT JOIN JDT1 J
       ON J."Account" = A."AcctCode"
      AND J."RefDate" <= TO_DATE('2026-09-30', 'YYYY-MM-DD')
WHERE A."Postable" = 'Y'
  AND A."GroupMask" IN (1, 2, 3)
GROUP BY A."AcctCode", A."AcctName", A."GroupMask", A."Levels"
HAVING SUM(IFNULL(J."Debit", 0) - IFNULL(J."Credit", 0)) <> 0
ORDER BY A."GroupMask", A."AcctCode";

Notice the Left Join with the date inside the join condition and not in the WHERE. If you move that filter down, the Left Join degrades into an INNER JOIN and you lose the accounts with no activity in the period. It is a classic.

Query 3: Check That the SAP Business One Balance Sheet Ties Out

This is the query you will use most during a close. It calculates assets, liabilities, equity and the profit for the year, and tells you whether the balance sheet ties out or by how much it is off.

SQL Server

-- Verificacion de cuadratura Activo = Pasivo + Patrimonio + Resultado
DECLARE @FechaCorte  DATE = '2026-09-30';
DECLARE @InicioAnio  DATE = '2026-01-01';
WITH Saldos AS (
    SELECT
        A.GroupMask,
        SUM(ISNULL(J.Debit, 0) - ISNULL(J.Credit, 0)) AS Saldo
    FROM OACT A
    INNER JOIN JDT1 J ON J.Account = A.AcctCode
    WHERE A.Postable = 'Y'
      AND J.RefDate <= @FechaCorte
      AND (A.GroupMask IN (1, 2, 3) OR J.RefDate >= @InicioAnio)
    GROUP BY A.GroupMask
)
SELECT
    SUM(CASE WHEN GroupMask = 1 THEN Saldo ELSE 0 END)           AS Activo,
    SUM(CASE WHEN GroupMask = 2 THEN Saldo ELSE 0 END) * -1      AS Pasivo,
    SUM(CASE WHEN GroupMask = 3 THEN Saldo ELSE 0 END) * -1      AS Patrimonio,
    SUM(CASE WHEN GroupMask BETWEEN 4 AND 8 THEN Saldo ELSE 0 END) * -1 AS ResultadoEjercicio,
    SUM(CASE WHEN GroupMask = 1 THEN Saldo ELSE 0 END)
      + SUM(CASE WHEN GroupMask BETWEEN 2 AND 8 THEN Saldo ELSE 0 END) AS Descuadre
FROM Saldos;

SAP HANA

-- Verificacion de cuadratura Activo = Pasivo + Patrimonio + Resultado
WITH "Saldos" AS (
    SELECT
        A."GroupMask" AS "GM",
        SUM(IFNULL(J."Debit", 0) - IFNULL(J."Credit", 0)) AS "Saldo"
    FROM OACT A
    INNER JOIN JDT1 J ON J."Account" = A."AcctCode"
    WHERE A."Postable" = 'Y'
      AND J."RefDate" <= TO_DATE('2026-09-30', 'YYYY-MM-DD')
      AND (A."GroupMask" IN (1, 2, 3)
           OR J."RefDate" >= TO_DATE('2026-01-01', 'YYYY-MM-DD'))
    GROUP BY A."GroupMask"
)
SELECT
    SUM(CASE WHEN "GM" = 1 THEN "Saldo" ELSE 0 END)            AS "Activo",
    SUM(CASE WHEN "GM" = 2 THEN "Saldo" ELSE 0 END) * -1       AS "Pasivo",
    SUM(CASE WHEN "GM" = 3 THEN "Saldo" ELSE 0 END) * -1       AS "Patrimonio",
    SUM(CASE WHEN "GM" BETWEEN 4 AND 8 THEN "Saldo" ELSE 0 END) * -1 AS "ResultadoEjercicio",
    SUM(CASE WHEN "GM" = 1 THEN "Saldo" ELSE 0 END)
      + SUM(CASE WHEN "GM" BETWEEN 2 AND 8 THEN "Saldo" ELSE 0 END) AS "Descuadre"
FROM "Saldos";

The column Mismatch must return zero. If it returns anything else, you have a journal entry with a misclassified account or a movement dated outside the fiscal year.

SAP Business One Balance Sheet - checking that the accounts tie out
The reconciliation check is the query you will use most during a close.

Variations and real-world use cases

Comparing two cut-off dates

Duplicate the balance block with two different dates and join them by AcctCode. That gives you the monthly variation of each account, which is the natural input for an indirect cash flow statement.

Filtering by branch or cost center

If you use multi-branch, add J.BPLId = 1 to the WHERE. For cost dimensions, the fields are J.ProfitCode, J.OcrCode2 and so on. Keep in mind that a balance sheet by cost center rarely ties out on its own, because treasury entries almost never carry a dimension.

Excluding closing entries

Annual closing entries travel with OJDT.TransType = -2. To see the balance sheet before the close, join to OJDT by TransId and discard that type. For example, this helps when you want to rebuild a historical balance sheet that has already been closed.

Balance sheet in system currency

If your company handles local currency and system currency separately, swap Debit and Credit by SYSDeb and SYSCred. The fields FCDebit and FCCredit hold the foreign currency of each line and only make sense account by account.

Best practices and common mistakes

Here are five things I learned the hard way through long closes.

Do not compare against the report without setting the same branch filter. The standard report remembers the last filter you used, even across sessions (a SAP design decision that still annoys me). Therefore, before declaring a mismatch, verify that both sides are looking at the same universe of data.

Save the query as a view, not as a loose query. A view in the database is versioned, documented and can be consumed from Power BI. A query in the Query Manager lives hidden in a folder nobody reviews. Besides, the view lets you use the same logic in Crystal Reports without copying and pasting SQL.

Watch out for accounts reclassified mid-year. If somebody changes the GroupMask of an account in August, every prior movement is reclassified retroactively, because the group lives on the account and not on the journal entry. As a result, a March balance sheet you issued months ago may stop reproducing. It is the kind of detail you only learn when it happens to you.

Never use WITH (NOLOCK) during a close. On a database with postings in progress you can read half-written rows and get a balance sheet that does not tie out for reasons that do not exist. In HANA the problem does not apply, because its isolation model is different.

Validate against the general ledger before publishing any figure. Take two or three large accounts, pull their ledger in the finance module and compare the closing balance. If those tie out, the rest almost always ties out.

Common Mistakes When Building the SAP Business One Balance Sheet

  • Forgetting Postable = 'Y'. Result: balances duplicated or tripled depending on the depth of the chart of accounts.
  • Putting the date in the WHERE of a Left Join. Result: accounts with no activity disappear.
  • Restricting by start date on balance sheet accounts. Result: you lose the accumulated balance from prior years.
  • Ignoring the profit for the year. Result: the balance sheet does not tie out and you blame accounting.
  • using Debit when the company operates in a different system currency. Result: conversion differences that look like accounting errors.

Official SAP Resources

To go deeper, these are the starting points I use:

  • SAP Help Portal — SAP Business One, functional documentation for the finance module.
  • The document SAP Business One Database Tables Reference, which describes OACT, JDT1 and OJDT field by field.
  • The SAP Community, where the threads in the finance area often solve mismatch cases that are not documented anywhere else.

Conclusion

Building the SAP Business One Balance Sheet with SQL does not replace the standard report, and it does not try to: what it does is give you a second, independent source to contrast against, so that when a difference appears between what the system says and what your gut says, you have a way to settle the argument with data instead of opinions. Accounting stops being a black box. That is worth far more than saving a few clicks.

I will leave you a concrete exercise for this week: run Query 3 as of last month's close and compare the field Mismatch against zero. If it returns zero, you already have a permanent control tool. If it does not return zero, you have just found something that had been hidden for months.

If this was useful, take a look at the Profit and Loss Statement and Account Determination tutorials on the blog too. They are the two pieces that complete the accounting map of your ERP.

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