Start a project

Customer aging report (AR aging)

Open invoice balance per customer in 0–30, 31–60, 61–90 and 90+ day buckets by due date.

Tables: OINVUse: Collections follow-up and credit control.

Tool

SELECT T0.CardCode, T0.CardName,
  SUM(CASE WHEN DATEDIFF(day, T0.DocDueDate, GETDATE()) <= 30 THEN T0.DocTotal - T0.PaidToDate ELSE 0 END) AS Days0to30,
  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()) BETWEEN 61 AND 90 THEN T0.DocTotal - T0.PaidToDate ELSE 0 END) AS Days61to90,
  SUM(CASE WHEN DATEDIFF(day, T0.DocDueDate, GETDATE()) > 90 THEN T0.DocTotal - T0.PaidToDate ELSE 0 END) AS Over90,
  SUM(T0.DocTotal - T0.PaidToDate) AS TotalOpen
FROM OINV T0
WHERE T0.DocStatus = 'O' AND T0.CANCELED = 'N'
GROUP BY T0.CardCode, T0.CardName
ORDER BY TotalOpen DESC
Need your UDFs in this report, or a dashboard? We extend it for your company.Customize it →

What this query answers

The credit controller prepares the weekly collections list and the CFO wants to know how much customer money is stuck beyond 60 or 90 days. This splits each customer's open invoice balance into age buckets by due date.

Sample output

Illustrative demo values. Your columns are the same; the numbers come from your company.

CardCodeCardNameDays0to30Days31to60Days61to90Over90TotalOpen
C20000Acme Trading1240053000210019800
C30000Northwind Retail875003200011950
C40000Blue Harbor Foods25001800046008900
C50000Summit Supplies00031503150

SQL Server vs SAP HANA

Each DATEDIFF(day, T0.DocDueDate, GETDATE()) becomes DAYS_BETWEEN(T0."DocDueDate", CURRENT_TIMESTAMP). The argument order is the same (start, end), so a positive result still means past due and the bucket limits do not change.

Common errors and fixes

  • Totals do not match the standard Customer Receivables Aging report: This query reads open A/R invoices only. Open credit notes, down payments and payments on account are not deducted, so the standard report can be lower.
  • Invoices that are not due yet sit in the 0-30 bucket: Not-yet-due invoices give a negative day count, which matches <= 30. Add a separate NotDue bucket (days <= 0) if you want to separate them.
  • Amounts look wrong for foreign-currency customers: DocTotal and PaidToDate are in local currency. Use DocTotalFC - PaidFC to age in the document currency.

Need this report built into SAP Business One?

A saved query answers the question once. We build B2B customer portals for SAP Business One: customers see their prices, stock, order status, invoices and statements, and their orders land in SAP as sales orders. Or hire a SAP Business One developer for the whole job, fixed price per phase.

Finance

Related queries

Table reference: OINV table (A/R Invoice (header))

How it works

Three steps, no signup

1

Copy the right version

Use the SQL Server tab for MS SQL databases and the HANA tab for SAP B1 on HANA.

2

Open Query Generator

In SAP Business One go to Tools → Queries → Query Generator, paste and click Execute.

3

Save and share

Click Save, pick a category and give the query a name. Your team can run it from Query Manager.

FAQ

Questions about this tool

How do I run the customer aging report (ar 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 OINV 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.

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.