If your general manager asks you today «how much cash will we have available in 30 days?» and you need to open Excel to answer, you cash flow SAP Business One It is stuck in the last century. The information exists within the ERP, but most companies consult it as if it were a dusty file, not as a decision-making compass.
Consequently, critical decisions regarding vendor payments, credit lines, or investment postponements are made with outdated data or intuition. Therefore, in this tutorial you will build a projected cash flow report in SAP Business One using ready-to-execute SQL queries, both in SQL Server and SAP HANA. In the end, you will have a real-time view of your liquidity by aging bucket, without Excel and without waiting.

Why your company needs a projected cash flow report
The native Cash Flow Forecast module of SAP Business One is useful, but it has limitations. First, it does not easily integrate into BI dashboards or automated emails. Furthermore, its structure does not adapt to the reality of each company: not everyone handles the same buckets, the same relevant banks, or the same collection logic.
For example, a Chilean industrial company that sells on 60-day credit doesn't want to see the same thing as a retailer with cash collection. As a result, relying solely on the standard report is like navigating with a generic map when what you need is the specific nautical chart of your coast. In this way, a SQL query gives you total control over the logic, buckets, filters, and the way the information is presented.
Build your own report of cash flow SAP Business One With SQL, it gives you three concrete advantages. First, instant execution from Query Manager or Crystal Reports. Second, direct integration with Power BI, Tableau, or any BI tool. Third, email automation through Alerts or external tools like scheduled task tools.
Prerequisites before running the queries
Before you begin, make sure your instance meets these basic requirements:
- SAP Business One version 9.3 or higher, on SQL Server 2014+ or SAP HANA
- Access to Query Manager with read permissions on OINV, OPCH, OJDT, and OACT
- Bank accounting accounts correctly identified (ideally with a prefix or segment of the chart of accounts)
- Sales and purchase invoices recorded with actual due dates (DocDueDate)
- If you use partial payments, make sure the PaidToDate field correctly reflects what has been charged or paid.
However, if your company does not have reliable due dates, this tutorial will serve a double purpose: first, it will highlight the problem; second, it will give you the exact metric to fix the process from the root.
Step-by-step tutorial: Build the SAP Business One cash flow
The logic of the report is broken down into three blocks. First, we calculate the current bank balance. Next, we add the open accounts receivable grouped by aging bucket. Finally, we subtract the open accounts payable using the same buckets.
Step 1: Identify the bank accounts
In SAP Business One, banks live in the OACT table (chart of accounts). Therefore, the first step is to locate the segment code or prefix that your chart of accounts uses for banks. In most Latin American implementations, bank accounts are under the «Current Asset» category with a clear prefix (for example, 1101 or 11010101).
For this tutorial, we will use the prefix as an example '1101%'. However, you must adjust it to your actual chart of accounts.
Step 2: Query of the current bank balance
SQL Server
-- Current Bank Balances - SQL Server
SELECT
T0.AcctCode AS 'Account Code',
T0.AcctName AS 'Bank',
T0.CurrTotal AS 'Current Balance',
T0.ActCurr AS 'Currency'
FROM OACT T0
WHERE T0.AcctCode LIKE '1101%'
AND T0.Postable = 'Y'
AND T0.FrozenFor = 'N'
ORDER BY T0.AcctCode;
SAP HANA
-- Current Bank Balances - SAP HANA
SELECT
T0."AcctCode" AS "Account Code",
T0."AcctName" AS "Bank",
T0."CurrTotal" AS "Current Balance",
T0."ActCurr" AS "Currency"
FROM OACT T0
WHERE T0."AcctCode" LIKE '1101%'
AND T0."Postable" = 'Y'
AND T0."FrozenFor" = 'N'
ORDER BY T0."AcctCode";
As a result, you get the real-time bank balance. This way, you avoid the classic lag of Excel-exported files that age as soon as they are opened.

Step 3: open accounts receivable by aging bucket
Here we build the positive cash flow column. We take each open sales invoice (OINV.DocStatus = ‘O’), subtract the amount already collected (PaidToDate), and classify it by days to maturity from today. In addition, we include open customer credit memos (ORIN) by subtracting that amount, because they represent money that must be refunded or applied.
SQL Server
-- Open accounts receivable by bucket - SQL Server
SELECT
CASE
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) < 0 THEN '1. Overdue'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 7 THEN '2. Next 7 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 15 THEN '3. 8 to 15 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 30 THEN '4. 16 to 30 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 60 THEN '5. 31 to 60 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END AS 'Bucket',
SUM(T0.DocTotal - T0.PaidToDate) AS 'Amount Receivable'
FROM OINV T0
WHERE T0.DocStatus = 'O'
AND T0.CANCELED = 'N'
GROUP BY
CASE
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) < 0 THEN '1. Overdue'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 7 THEN '2. Next 7 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 15 THEN '3. 8 to 15 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 30 THEN '4. 16 to 30 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 60 THEN '5. 31 to 60 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END
ORDER BY 1;
SAP HANA
-- Open accounts receivable by bucket - SAP HANA
SELECT
CASE
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") < 0 THEN '1. Overdue'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 7 THEN '2. Next 7 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 15 THEN '3. 8 to 15 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 30 THEN '4. 16 to 30 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 60 THEN '5. 31 to 60 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END AS "Bucket",
SUM(T0."DocTotal" - T0."PaidToDate") AS "Amount Receivable"
FROM OINV T0
WHERE T0."DocStatus" = 'O'
AND T0."CANCELED" = 'N'
GROUP BY
CASE
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") < 0 THEN '1. Overdue'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 7 THEN '2. Next 7 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 15 THEN '3. 8 to 15 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 30 THEN '4. 16 to 30 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 60 THEN '5. 31 to 60 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END
ORDER BY 1;
Step 4: Open accounts payable by bucket
The logic is exactly the same, but inverted. We take the open vendor invoices (OPCH.DocStatus = ‘O’). As a result, we know how much and when we are going to disburse.
SQL Server
-- Open accounts payable by bucket - SQL Server
SELECT
CASE
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) < 0 THEN '1. Overdue'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 7 THEN '2. Next 7 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 15 THEN '3. 8 to 15 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 30 THEN '4. 16 to 30 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 60 THEN '5. 31 to 60 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END AS 'Bucket',
SUM(T0.DocTotal - T0.PaidToDate) AS 'Amount Payable'
FROM OPCH T0
WHERE T0.DocStatus = 'O'
AND T0.CANCELED = 'N'
GROUP BY
CASE
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) < 0 THEN '1. Overdue'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 7 THEN '2. Next 7 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 15 THEN '3. 8 to 15 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 30 THEN '4. 16 to 30 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 60 THEN '5. 31 to 60 days'
WHEN DATEDIFF(DAY, GETDATE(), T0.DocDueDate) <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END
ORDER BY 1;
SAP HANA
-- Open Accounts Payable by bucket - SAP HANA
SELECT
CASE
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") < 0 THEN '1. Overdue'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 7 THEN '2. Next 7 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 15 THEN '3. 8 to 15 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 30 THEN '4. 16 to 30 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 60 THEN '5. 31 to 60 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END AS "Bucket",
SUM(T0."DocTotal" - T0."PaidToDate") AS "Amount Payable"
FROM OPCH T0
WHERE T0."DocStatus" = 'O'
AND T0."CANCELED" = 'N'
GROUP BY
CASE
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") < 0 THEN '1. Overdue'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 7 THEN '2. Next 7 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 15 THEN '3. 8 to 15 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 30 THEN '4. 16 to 30 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 60 THEN '5. 31 to 60 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, T0."DocDueDate") <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END
ORDER BY 1;
Consolidated query: the complete cash flow in a single view
Below we combine everything into a single report that delivers income, expenses, and net cash flow by bucket. Therefore, this is the query you will paste into Query Manager and save as your official liquidity view.
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.
SQL Server
-- Consolidated Projected Cash Flow - SQL Server
WITH BucketsCxC AS (
SELECT
CASE
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) < 0 THEN '1. Past Due'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 7 THEN '2. Next 7 Days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 15 THEN '3. 8 to 15 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 30 THEN '4. 16 to 30 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 60 THEN '5. 31 to 60 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END AS Bucket,
SUM(DocTotal - PaidToDate) AS AmountOwing
FROM OINV
WHERE DocStatus = 'O' AND CANCELED = 'N'
GROUP BY
CASE
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) < 0 THEN '1. Past due'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 7 THEN '2. Next 7 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 15 THEN '3. 8 to 15 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 30 THEN '4. 16 to 30 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 60 THEN '5. 31 to 60 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END
),
BucketsCxP AS (
SELECT
CASE
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) < 0 THEN '1. Past due'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 7 THEN '2. Next 7 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 15 THEN '3. 8 to 15 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 30 THEN '4. 16 to 30 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 60 THEN '5. 31 to 60 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END AS Bucket,
SUM(DocTotal - PaidToDate) AS AmountOwed
FROM OPCH
WHERE DocStatus = 'O' AND CANCELED = 'N'
GROUP BY
CASE
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) < 0 THEN '1. Past due'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 7 THEN '2. Next 7 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 15 THEN '3. 8 to 15 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 30 THEN '4. 16 to 30 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 60 THEN '5. 31 to 60 days'
WHEN DATEDIFF(DAY, GETDATE(), DocDueDate) <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END
)
SELECT
ISNULL(C.Bucket, P.Bucket) AS 'Bucket',
ISNULL(C.Accounts Receivable, 0) AS 'Expected Revenue',
ISNULL(P.Payable, 0) AS 'Committed Expenses',
ISNULL(C.Receivables, 0) - ISNULL(P.Payable, 0) AS 'Net Cash Flow'
FROM BucketsCxC C
FULL OUTER JOIN BucketsCxP P ON C.Bucket = P.Bucket
ORDER BY 1;
SAP HANA
-- Consolidated Projected Cash Flow - SAP HANA
WITH BucketsCxC AS (
SELECT
CASE
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") < 0 THEN '1. Past Due'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 7 THEN '2. Next 7 Days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 15 THEN '3. 8 to 15 Days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 30 THEN '4. 16 to 30 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 60 THEN '5. 31 to 60 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END AS "Bucket",
SUM("DocTotal" - "PaidToDate") AS "Outstanding"
FROM OINV
WHERE "DocStatus" = 'O' AND "CANCELED" = 'N'
GROUP BY
CASE
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") < 0 THEN '1. Past due'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 7 THEN '2. Next 7 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 15 THEN '3. 8 to 15 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 30 THEN '4. 16 to 30 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 60 THEN '5. 31 to 60 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END
),
BucketsCxP AS (
SELECT
CASE
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") < 0 THEN '1. Past due'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 7 THEN '2. Next 7 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 15 THEN '3. 8 to 15 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 30 THEN '4. 16 to 30 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 60 THEN '5. 31 to 60 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END AS "Bucket",
SUM("DocTotal" - "PaidToDate") AS "Amount Due"
FROM OPCH
WHERE "DocStatus" = 'O' AND "CANCELED" = 'N'
GROUP BY
CASE
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") < 0 THEN '1. Past due'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 7 THEN '2. Next 7 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 15 THEN '3. 8 to 15 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 30 THEN '4. 16 to 30 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 60 THEN '5. 31 to 60 days'
WHEN DAYS_BETWEEN(CURRENT_DATE, "DocDueDate") <= 90 THEN '6. 61 to 90 days'
ELSE '7. More than 90 days'
END
)
SELECT
IFNULL(C."Bucket", P."Bucket") AS "Bucket",
IFNULL(C."Accounts Receivable", 0) AS "Expected Revenue",
IFNULL(P."Payables", 0) AS "Committed Expenses",
IFNULL(C."Receivables", 0) - IFNULL(P."Payables", 0) AS "Net Cash Flow"
FROM BucketsCxC C
FULL OUTER JOIN BucketsCxP P ON C."Bucket" = P."Bucket"
ORDER BY 1;
Useful variations for real-world use cases
The consolidated query is the skeleton. However, in actual operation, you will need to adapt it. Below are three high-value variations.
Variation 1: filter by currency
If your company operates in pesos and dollars, add AND DocCur = 'CLP' (or the relevant currency) to the WHERE clause of each CTE. Therefore, you will be able to generate a currency-separated flow and avoid comparing apples and oranges in the payment decision.
Variation 2: Adjust buckets to your reality
If your business is long-cycle, the 7 and 15-day buckets are unnecessary. For example, a construction company might prefer buckets of 30, 60, 90, 120, and 180 days. Therefore, simply rewrite the ranges in the CASE.
Variation 3: include checks on hand and scheduled payments
For a more comprehensive view, add the received checks pending deposit (OCHF) and the scheduled payments (OPYD) next to income. However, this level of detail requires validating your payment setup in SAP. As a result, it is best to start with the base version and then enrich it.
Best practices and common mistakes
The first mistake I see in companies that already have this report is ignoring the quality of the due dates. Consequently, the projected cash flow gets distorted. If the sales department records all invoices with DocDueDate equal to DocDate, the report simply reproduces that lie and turns it into a financial strategy. Therefore, before presenting it to management, audit a sample and compare it with the actual sales terms.
The second mistake is confusing the book balance with the available bank balance. The bank's ledger account reflects what has been recorded, not necessarily what has been reconciled. As a result, if your reconciliation is lagging behind, the balance will be overly optimistic. In this way, this report becomes an ally in the reconciliation process: it forces you to keep it up to date.
The third mistake is not automating it. A query that is run manually every Monday loses half its value. Consequently, set up an alert that emails the workflow every morning, or connect it to Power BI with a daily refresh. True digital transformation begins when the data reaches the person who needs it on its own.
Finally, the fourth mistake is not including recurring entries (salaries, leasings, rent). The report shows only registered invoices, but fixed commitments also consume cash flow. Therefore, consider supplementing the report with a user table where you record recurring commitments and add them to the consolidated query with a UNION ALL.
Official SAP resources
To dive deeper, I recommend reviewing the official documentation. First, the SAP Help Portal maintains the technical reference for the OINV, OPCH, and OACT tables. In addition, the native Cash Flow Forecast module in SAP Business One for HANA has graphical capabilities that are worth exploring as a complement. Finally, the SAP Community is an excellent place to validate query variants and discover approaches from other consultants.
Conclusion: from reporting to actual liquidity control
Build your own report of cash flow SAP Business One With SQL, it is not a technical exercise. It is a shift in mindset. You go from looking at cash in the rearview mirror to anticipating the next 30, 60, or 90 days with real data from the ERP. This way, decisions regarding payments, collections, and financing are no longer based on intuition.
However, the report is only one piece. The real leap happens when you integrate this view into a weekly routine with your CFO, your sales manager, and your operations manager. As a result, you stop being the department that delivers information and start being the department that moves the needle for the business.
If you want to master this level of control over your SAP Business One and build reports that your general management consults every morning, subscribe to the Strategic Circle at hectorpincheira.com. Each article delivers tools ready to implement, without bloated theory and without filler. The difference between an average company and a leading one is not in the ERP they bought, but in how they use it.




