Vendor aging report (AP aging)
Open A/P invoice balance per vendor in due-date buckets.
Tool
SELECT T0.CardCode, T0.CardName, SUM(CASE WHEN DATEDIFF(day, T0.DocDueDate, GETDATE()) <= 0 THEN T0.DocTotal - T0.PaidToDate ELSE 0 END) AS NotDue, SUM(CASE WHEN DATEDIFF(day, T0.DocDueDate, GETDATE()) BETWEEN 1 AND 30 THEN T0.DocTotal - T0.PaidToDate ELSE 0 END) AS Days1to30, SUM(CASE WHEN DATEDIFF(day, T0.DocDueDate, GETDATE()) BETWEEN 31 AND 60 THEN T0.DocTotal - T0.PaidToDate ELSE 0 END) AS Days31to60, SUM(CASE WHEN DATEDIFF(day, T0.DocDueDate, GETDATE()) > 60 THEN T0.DocTotal - T0.PaidToDate ELSE 0 END) AS Over60, SUM(T0.DocTotal - T0.PaidToDate) AS TotalOpen FROM OPCH T0 WHERE T0.DocStatus = 'O' AND T0.CANCELED = 'N' GROUP BY T0.CardCode, T0.CardName ORDER BY TotalOpen DESC
SELECT T0."CardCode", T0."CardName", SUM(CASE WHEN DAYS_BETWEEN(T0."DocDueDate", CURRENT_TIMESTAMP) <= 0 THEN T0."DocTotal" - T0."PaidToDate" ELSE 0 END) AS "NotDue", SUM(CASE WHEN DAYS_BETWEEN(T0."DocDueDate", CURRENT_TIMESTAMP) BETWEEN 1 AND 30 THEN T0."DocTotal" - T0."PaidToDate" ELSE 0 END) AS "Days1to30", SUM(CASE WHEN DAYS_BETWEEN(T0."DocDueDate", CURRENT_TIMESTAMP) BETWEEN 31 AND 60 THEN T0."DocTotal" - T0."PaidToDate" ELSE 0 END) AS "Days31to60", SUM(CASE WHEN DAYS_BETWEEN(T0."DocDueDate", CURRENT_TIMESTAMP) > 60 THEN T0."DocTotal" - T0."PaidToDate" ELSE 0 END) AS "Over60", SUM(T0."DocTotal" - T0."PaidToDate") AS "TotalOpen" FROM OPCH T0 WHERE T0."DocStatus" = 'O' AND T0."CANCELED" = 'N' GROUP BY T0."CardCode", T0."CardName" ORDER BY "TotalOpen" DESC
What this query answers
When the finance manager plans this week's supplier payments, the question is which bills are already late and which can wait. This splits each vendor's open A/P invoices into not-due and overdue buckets.
Sample output
Illustrative demo values. Your columns are the same; the numbers come from your company.
| CardCode | CardName | NotDue | Days1to30 | Days31to60 | Over60 | TotalOpen |
|---|---|---|---|---|---|---|
| V10000 | Global Parts Co. | 15000 | 6200 | 0 | 0 | 21200 |
| V20000 | Metro Packaging | 4300 | 2750 | 1900 | 0 | 8950 |
| V23000 | Prime Logistics | 0 | 0 | 2400 | 3600 | 6000 |
SQL Server vs SAP HANA
DATEDIFF(day, T0.DocDueDate, GETDATE()) is replaced by DAYS_BETWEEN(T0."DocDueDate", CURRENT_TIMESTAMP) in all five expressions. The NotDue bucket (<= 0) keeps the same meaning because the argument order is unchanged.
Common errors and fixes
- Vendor totals are higher than the vendor statement: Open A/P credit notes and down payments are not subtracted. Add a UNION ALL from ORPC with negative amounts if suppliers issue credit notes often.
- Cancelled A/P invoices appear: Keep T0.CANCELED = 'N'. Cancelled invoices are closed, but the filter also guards against the cancellation documents being counted.
Need this report built into SAP Business One?
A saved query answers the question once. We build supplier portals for SAP Business One: vendors confirm purchase orders and delivery dates, upload invoices as A/P drafts and check payment status. Or hire a dedicated SAP B1 developer for the whole job, fixed price per phase.
Related queries
Table reference: OPCH table (A/P Invoice (header))
Three steps, no signup
Copy the right version
Use the SQL Server tab for MS SQL databases and the HANA tab for SAP B1 on HANA.
Open Query Generator
In SAP Business One go to Tools → Queries → Query Generator, paste and click Execute.
Save and share
Click Save, pick a category and give the query a name. Your team can run it from Query Manager.
Questions about this tool
How do I run the vendor aging report (ap aging) query in SAP Business One?
Copy the version that matches your database, open Tools → Queries → Query Generator, paste it in the SQL box and click Execute. Save it to reuse it later.
Which tables does this query use?
It reads OPCH from the standard SAP Business One schema. No user-defined fields are needed.
Can this be turned into a dashboard or alert?
Yes. We turn queries into Crystal reports, Excel reports that refresh themselves, SAP B1 alerts or WhatsApp messages for managers.
Built for SAP Business One teams
Need this inside SAP Business One?
We build add-ons, reports and integrations for SAP B1 on SQL Server and HANA. Tell us what you need and get a fixed price, usually within 24 hours.
