The invisible problem: inventory that ages without anyone noticing
Every day a product sits in your warehouse without moving, your company loses money. It is not an exaggeration: it is immobilized capital, wasted space, risk of obsolescence, and storage costs that quietly accumulate. The problem is that SAP Business One does not include a standard inventory aging report may show you this reality clearly.
Most companies review their inventory by quantity or by value, but few analyze it by time. And that is where the most costly decisions are hidden. In this tutorial, you are going to learn how to build a inventory aging report using SQL queries directly in the SAP Business One Query Manager, with configurable day ranges and warehouse-by-warehouse analysis.

Why do you need an inventory aging report?
An inventory aging report answers critical questions that standard reports do not cover:
How much inventory has not moved for more than 90 days? This is dead capital. In an industrial company, it can represent hundreds of thousands of dollars trapped in materials that no one needs right now.
What items are at risk of obsolescence? If a product has been in the warehouse for 180 days, you probably need to take action: liquidate, relocate, or adjust your purchasing parameters.
How is seniority distributed by warehouse? It is not the same to have old inventory in your main warehouse as it is in a remote storage facility. Location completely changes the action strategy.
Prerequisites
To implement these queries you need:
— Access to Query Manager from SAP Business One (Tools → Queries → Query Manager)
— Read permissions on the inventory tables (OITM, OITW, OINM, OBTN, OBTQ)
- Basic SQL knowledge (SELECT, JOIN, CASE, GROUP BY)
— SAP Business One 9.3 or higher (tables are compatible with previous versions, but date functions may vary)
The key tables you need to know
Before writing a single line of SQL, you need to understand the inventory data structure in SAP Business One:
OITM (Items Master Data): The item master data table. Here you can find the code, name, group, item type, and general properties. It is your starting point.
OITW (Items – Warehouses): Inventory by warehouse. Each record represents the quantity and cost of an item in a specific warehouse. Crucial for location-based analysis.
OINM (Inventory Journal): The inventory movement journal. Every entry, exit, transfer, and adjustment is recorded here with the date, quantity, warehouse, and source document. This is the table that allows us to calculate the actual aging.
OBTN / OBTQ (Batch Numbers / Batch Quantities): If you manage batches, these tables are your source of truth. OBTN has the batch receipt date and OBTQ the quantity per warehouse.

Step 1: Basic inventory aging query by last entry
This first query calculates the seniority based on the last entry date of each item in each warehouse. It is the most straightforward approach and works for items without batch management.
MS SQL Server version
SELECT
T0.ItemCode AS 'Item Code',
T0.ItemName AS 'Description',
T1.WhsCode AS 'Warehouse',
T1.OnHand AS 'Current Stock',
CAST(T1.OnHand * T1.AvgPrice AS DECIMAL(15,2))
AS 'Inventory Value',
MAX(T2.DocDate) AS 'Last Receipt',
DATEDIFF(DAY, MAX(T2.DocDate), GETDATE())
AS 'Days in Warehouse',
CASE
WHEN DATEDIFF(DAY, MAX(T2.DocDate), GETDATE()) <= 30
THEN '0–30 days'
WHEN DATEDIFF(DAY, MAX(T2.DocDate), GETDATE()) <= 60
THEN '31–60 days'
WHEN DATEDIFF(DAY, MAX(T2.DocDate), GETDATE()) <= 90
THEN '61–90 days'
WHEN DATEDIFF(DAY, MAX(T2.DocDate), GETDATE()) <= 180
THEN '91–180 days'
ELSE 'More than 180 days'
END AS 'Age Range'
FROM OITM T0
INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode
INNER JOIN OINM T2 ON T2.ItemCode = T0.ItemCode
AND T2.Warehouse = T1.WhsCode
AND T2.InQty > 0
WHERE T1.OnHand > 0
AND T0.InvntItem = 'Y'
GROUP BY T0.ItemCode, T0.ItemName,
T1.WhsCode, T1.OnHand, T1.AvgPrice
ORDER BY 'Days in Warehouse' DESCSAP HANA version
SELECT
T0."ItemCode" AS "Item Code",
T0."ItemName" AS "Description",
T1."WhsCode" AS "Warehouse",
T1."OnHand" AS "Current Stock",
ROUND(T1."OnHand" * T1."AvgPrice", 2)
AS "Inventory Value",
MAX(T2."DocDate") AS "Last Receipt",
DAYS_BETWEEN(MAX(T2."DocDate"), CURRENT_DATE)
AS "Days in Warehouse",
CASE
WHEN DAYS_BETWEEN(MAX(T2."DocDate"), CURRENT_DATE) <= 30
THEN '0–30 days'
WHEN DAYS_BETWEEN(MAX(T2."DocDate"), CURRENT_DATE) <= 60
THEN '31–60 days'
WHEN DAYS_BETWEEN(MAX(T2."DocDate"), CURRENT_DATE) <= 90
THEN '61–90 days'
WHEN DAYS_BETWEEN(MAX(T2."DocDate"), CURRENT_DATE) <= 180
THEN '91–180 days'
ELSE 'More than 180 days'
END AS "Age Range"
FROM OITM T0
INNER JOIN OITW T1 ON T0."ItemCode" = T1."ItemCode"
INNER JOIN OINM T2 ON T2."ItemCode" = T0."ItemCode"
AND T2."Warehouse" = T1."WhsCode"
AND T2."InQty" > 0
WHERE T1."OnHand" > 0
AND T0."InvntItem" = 'Y'
GROUP BY T0."ItemCode", T0."ItemName",
T1."WhsCode", T1."OnHand", T1."AvgPrice"
ORDER BY "Days in Warehouse" DESCWhat does this query do? Find the latest entry date (InQty > 0) in the OINM table for each item-warehouse combination, and calculate how many days have elapsed since then. The results are classified into aging ranges that you can customize according to your business needs.
Step 2: Advanced query with batch analysis (Batch Management)
If your company handles items with batch management —something common in the food, pharmaceutical, and chemical industries— you need a different approach. The age must be calculated in batch, not per item, because each batch has its own entry date.
MS SQL Server version
SELECT
T0.ItemCode AS 'Code',
T0.ItemName AS 'Description',
T1.DistNumber AS 'Lot No.',
T2.WhsCode AS 'Warehouse',
T2.Quantity AS 'Lot Quantity',
T1.InDate AS 'Receipt Date',
T1.ExpDate AS 'Expiration Date',
DATEDIFF(DAY, T1.InDate, GETDATE())
AS 'Days Past Due',
CASE
WHEN T1.ExpDate IS NOT NULL
AND T1.ExpDate < GETDATE()
THEN 'EXPIRED'
WHEN T1.ExpDate IS NOT NULL
AND DATEDIFF(DAY, GETDATE(), T1.ExpDate) <= 30
THEN 'NEAR EXPIRATION'
ELSE 'CURRENT'
END AS 'Batch Status',
CASE
WHEN DATEDIFF(DAY, T1.InDate, GETDATE()) <= 30
THEN '0–30 days'
WHEN DATEDIFF(DAY, T1.InDate, GETDATE()) <= 60
THEN '31–60 days'
WHEN DATEDIFF(DAY, T1.InDate, GETDATE()) <= 90
THEN '61–90 days'
WHEN DATEDIFF(DAY, T1.InDate, GETDATE()) <= 180
THEN '91–180 days'
ELSE 'More than 180 days'
END AS 'Age Range'
FROM OITM T0
INNER JOIN OBTN T1 ON T1.ItemCode = T0.ItemCode
INNER JOIN OBTQ T2 ON T2.AbsEntry = T1.AbsEntry
WHERE T2.Quantity > 0
AND T0.InvntItem = 'Y'
ORDER BY 'Days on Hand' DESCThis query is especially valuable because, in addition to the seniority range, it includes a batch status indicator: detects expired lots and lots close to expiring (less than 30 days). In regulated industries, this information can prevent fines, returns, and quality issues.
Step 3: Executive summary — inventory value by age range
The previous queries show the detail line by line. But when you need to present results to management, you need a consolidated summary. This query groups the total inventory value by age range:
MS SQL Server version
SELECT
Aging.AgeRange,
COUNT(DISTINCT Aging.ItemCode)
AS 'Items',
SUM(Aging.CurrentStock) AS 'Total Units',
CAST(SUM(Aging.InventoryValue) AS DECIMAL(15,2))
AS 'Total Value',
CAST(SUM(Aging.InventoryValue) * 100.0 /
SUM(SUM(Aging.InventoryValue)) OVER()
AS DECIMAL(5,2))
AS '% of Total'
FROM (
SELECT
T0.ItemCode,
T1.OnHand AS ActualStock,
T1.OnHand * T1.AvgPrice AS InventoryValue,
CASE
WHEN DATEDIFF(DAY, MAX(T2.DocDate), GETDATE()) <= 30
THEN '1. Fresh (0–30 days)'
WHEN DATEDIFF(DAY, MAX(T2.DocDate), GETDATE()) <= 60
THEN '2. Normal (31–60 days)'
WHEN DATEDIFF(DAY, MAX(T2.DocDate), GETDATE()) <= 90
THEN '3. Slow (61–90 days)'
WHEN DATEDIFF(DAY, MAX(T2.DocDate), GETDATE()) <= 180
THEN '4. At Risk (91–180 days)'
ELSE '5. Critical (+180 days)'
END AS AgeRange
FROM OITM T0
INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode
INNER JOIN OINM T2 ON T2.ItemCode = T0.ItemCode
AND T2.Warehouse = T1.WhsCode
AND T2.InQty > 0
WHERE T1.OnHand > 0
AND T0.InvntItem = 'Y'
GROUP BY T0.ItemCode, T1.OnHand, T1.AvgPrice
) Aging
GROUP BY Aging.AgingRange
ORDER BY Aging.AgingRangeThe result is a summary table showing how many items and what percentage of the total value of your inventory fall into each range. If you find that 40% of your capital is tied up in inventory for more than 90 days, you have a clear problem that requires immediate action.

Useful variations and customizations
Filter by item group: add AND T0.ItmsGrpCod = [Group ID] in the WHERE clause to analyze only one product family.
Filter by specific warehouse: add AND T1.WhsCode = 'TU_ALMACEN' to focus on a location.
Change seniority ranges: The 30-60-90-180 day intervals are a standard, but every industry has its own rhythm. In food, perhaps 7-15-30-60 days is more appropriate. In industrial spare parts, 90-180-365-730 days may make more sense.
Add the estimated storage cost: If you know your daily storage cost per unit, you can multiply the days of age by that factor to obtain the actual cost of holding that inventory.
Best practices and common mistakes
Do not confuse the last entry with the first entry. The query uses MAX(DocDate) to get the most recent entry. If an item constantly receives stock, the age resets. If you need a true FIFO (First In, First Out) analysis, you must use the FIFO layer tables (OIVL) or batches (OBTN).
Watch out for items with no inbound movements. If an item has stock but never had an incoming record in OINM (for example, it was uploaded via opening balance), the INNER JOIN will exclude it. Consider using LEFT JOIN and handling NULLs with ISNULL() or COALESCE() to show these items as «No entry date».
Exclude non-inventory items. The filter T0.InvntItem = 'Y' It is essential. Without it, you would include unmanaged services and inventory items, distorting your analysis.
Schedule the periodic execution. This report is valuable when reviewed frequently. Set it up as a saved query in Query Manager and review it weekly in your inventory planning meeting.
Validate against the standard valuation report. Compare your query totals with the standard SAP Business One inventory valuation report (Inventory → Inventory Reports → Inventory Valuation Report). The numbers must match. If they don't match, review your filters and joins.
Official resources
To delve deeper into the tables and fields used in these queries, consult these SAP resources:
- SAP Help – Inventory Aging ReportOfficial SAP Business One standard report documentation.
- SAP SDK – OITM Table ReferenceData dictionary of the master item table.
- SAP Community – Query Report Inventory AgingCommunity discussions with additional examples.
Conclusion: inventory that is not measured is not managed
Building an inventory aging report in SAP Business One is not a technical exercise: it is a strategic decision. Every query you run gives you visibility into trapped cash, hidden risks, and optimization opportunities that no standard report will ever show you.
The true value does not lie in having the perfect SQL, but in acting on what you discover. Do you have items sitting for more than 180 days without moving? It is time to decide: do you liquidate, renegotiate with suppliers, or adjust your planning parameters? The query doesn't give the answer. Your judgment as a leader does. But without the query, you wouldn't even know you need to make that decision.
Do you already have a process to review your inventory aging? If not, today is the best day to start.




