Batches expiring in the next 60 days
Batch numbers with stock that expire within 60 days, per warehouse.
Tool
SELECT T0.ItemCode, T0.DistNumber AS BatchNumber, T0.ExpDate, T1.WhsCode, T1.Quantity, DATEDIFF(day, GETDATE(), T0.ExpDate) AS DaysLeft FROM OBTN T0 INNER JOIN OBTQ T1 ON T0.AbsEntry = T1.MdAbsEntry WHERE T1.Quantity > 0 AND T0.ExpDate IS NOT NULL AND T0.ExpDate <= DATEADD(day, 60, GETDATE()) ORDER BY T0.ExpDate
SELECT T0."ItemCode", T0."DistNumber" AS "BatchNumber", T0."ExpDate", T1."WhsCode", T1."Quantity", DAYS_BETWEEN(CURRENT_TIMESTAMP, T0."ExpDate") AS "DaysLeft" FROM OBTN T0 INNER JOIN OBTQ T1 ON T0."AbsEntry" = T1."MdAbsEntry" WHERE T1."Quantity" > 0 AND T0."ExpDate" IS NOT NULL AND T0."ExpDate" <= ADD_DAYS(CURRENT_TIMESTAMP, 60) ORDER BY T0."ExpDate"
What this query answers
In a food, pharma or chemicals business the quality lead checks weekly which batches will expire soon and where they sit. This list helps decide what to sell first, discount or quarantine, including batches that have already expired.
Sample output
Illustrative demo values. Your columns are the same; the numbers come from your company.
| ItemCode | BatchNumber | ExpDate | WhsCode | Quantity | DaysLeft |
|---|---|---|---|---|---|
| F10001 | L260915 | 2026-10-20 | 01 | 24 | -4 |
| F10003 | L261002 | 2026-11-05 | 01 | 120 | 12 |
| F10001 | L261010 | 2026-11-30 | 02 | 60 | 37 |
| F10007 | L261018 | 2026-12-18 | 01 | 300 | 55 |
SQL Server vs SAP HANA
DATEDIFF(day, GETDATE(), T0.ExpDate) becomes DAYS_BETWEEN(CURRENT_TIMESTAMP, T0."ExpDate"), and DATEADD(day, 60, GETDATE()) becomes ADD_DAYS(CURRENT_TIMESTAMP, 60). Keep today as the first argument, otherwise DaysLeft changes sign.
Common errors and fixes
- Already expired batches appear with negative days: That is intended, because expired stock still needs action. Add AND T0.ExpDate >= GETDATE() (CURRENT_DATE on HANA) to hide them.
- An item with batches does not show up: The item may be serial-managed, not batch-managed (serials live in OSRN/OSRQ), or the expiry date was never entered on the batch.
Need this report built into SAP Business One?
A saved query answers the question once. We build iOS and Android apps for SAP Business One: warehouse scanning, stock counts, sales orders and approvals on the Service Layer. Or hire a dedicated SAP B1 developer for the whole job, fixed price per phase.
Related queries
Table reference: OBTN table (Batch Numbers (master data)) · OBTQ table (Batch Number Quantities (per warehouse)) · OITM table (Items (item master data))
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 batches expiring in the next 60 days 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 OBTN, OBTQ 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.
