Start a project

Stock by warehouse

On hand, committed, ordered and available quantity per item and warehouse.

Tables: OITW, OITMUse: Daily stock checks and sales availability.

Tool

SELECT T0.ItemCode, T1.ItemName, T0.WhsCode, T0.OnHand, T0.IsCommited, T0.OnOrder,
  T0.OnHand - T0.IsCommited + T0.OnOrder AS Available
FROM OITW T0
INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
WHERE T0.OnHand <> 0 OR T0.IsCommited <> 0 OR T0.OnOrder <> 0
ORDER BY T0.ItemCode, T0.WhsCode
Need your UDFs in this report, or a dashboard? We extend it for your company.Customize it →

What this query answers

A sales rep is on the phone with a customer and needs to know whether an item can be promised, and from which warehouse. This shows what is physically there, what is already promised to other orders and what is on the way.

You can also ask ChatGPT or Claude for stock levels straight from SAP Business One, through a read-only MCP server.

Sample output

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

ItemCodeItemNameWhsCodeOnHandIsCommitedOnOrderAvailable
A00001Laser Printer 1420011203050140
A00001Laser Printer 142002400040
A00002Inkjet Printer 600011520105
A00003Toner Cartridge Color01082517

SQL Server vs SAP HANA

The SQL is unchanged except for quoting; the misspelled SAP column must be written "IsCommited" (one t) in double quotes. The OR conditions and the Available calculation work the same on HANA.

Variations

Only nettable warehouses

SQL Server

SELECT T0.ItemCode, T0.WhsCode, T0.OnHand, T0.IsCommited, T0.OnOrder,
  T0.OnHand - T0.IsCommited + T0.OnOrder AS Available
FROM OITW T0
INNER JOIN OWHS T2 ON T0.WhsCode = T2.WhsCode
WHERE T2.Nettable = 'Y'
  AND (T0.OnHand <> 0 OR T0.IsCommited <> 0 OR T0.OnOrder <> 0)
ORDER BY T0.ItemCode, T0.WhsCode

SAP HANA

SELECT T0."ItemCode", T0."WhsCode", T0."OnHand", T0."IsCommited", T0."OnOrder",
  T0."OnHand" - T0."IsCommited" + T0."OnOrder" AS "Available"
FROM OITW T0
INNER JOIN OWHS T2 ON T0."WhsCode" = T2."WhsCode"
WHERE T2."Nettable" = 'Y'
  AND (T0."OnHand" <> 0 OR T0."IsCommited" <> 0 OR T0."OnOrder" <> 0)
ORDER BY T0."ItemCode", T0."WhsCode"

Total per item across all warehouses

SQL Server

SELECT T0.ItemCode, T1.ItemName, SUM(T0.OnHand) AS OnHand,
  SUM(T0.IsCommited) AS IsCommited, SUM(T0.OnOrder) AS OnOrder,
  SUM(T0.OnHand - T0.IsCommited + T0.OnOrder) AS Available
FROM OITW T0
INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
GROUP BY T0.ItemCode, T1.ItemName
ORDER BY T0.ItemCode

SAP HANA

SELECT T0."ItemCode", T1."ItemName", SUM(T0."OnHand") AS "OnHand",
  SUM(T0."IsCommited") AS "IsCommited", SUM(T0."OnOrder") AS "OnOrder",
  SUM(T0."OnHand" - T0."IsCommited" + T0."OnOrder") AS "Available"
FROM OITW T0
INNER JOIN OITM T1 ON T0."ItemCode" = T1."ItemCode"
GROUP BY T0."ItemCode", T1."ItemName"
ORDER BY T0."ItemCode"

Hide zero-stock rows

SQL Server

SELECT T0.ItemCode, T1.ItemName, T0.WhsCode, T0.OnHand
FROM OITW T0
INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
WHERE T0.OnHand > 0
ORDER BY T0.ItemCode, T0.WhsCode

SAP HANA

SELECT T0."ItemCode", T1."ItemName", T0."WhsCode", T0."OnHand"
FROM OITW T0
INNER JOIN OITM T1 ON T0."ItemCode" = T1."ItemCode"
WHERE T0."OnHand" > 0
ORDER BY T0."ItemCode", T0."WhsCode"

Bin-level stock (bin locations enabled)

SQL Server

SELECT T0.ItemCode, T1.WhsCode, T1.BinCode, T0.OnHandQty
FROM OIBQ T0
INNER JOIN OBIN T1 ON T0.BinAbs = T1.AbsEntry
WHERE T0.OnHandQty <> 0
ORDER BY T0.ItemCode, T1.BinCode

SAP HANA

SELECT T0."ItemCode", T1."WhsCode", T1."BinCode", T0."OnHandQty"
FROM OIBQ T0
INNER JOIN OBIN T1 ON T0."BinAbs" = T1."AbsEntry"
WHERE T0."OnHandQty" <> 0
ORDER BY T0."ItemCode", T1."BinCode"

Common errors and fixes

  • Stock looks higher than what the warehouse can sell: Non-nettable warehouses (for example damaged goods or consignment) are included. Join OWHS and filter Nettable = 'Y'.
  • Totals do not match OITM.OnHand per warehouse: OITM.OnHand is the total across all warehouses. The per-warehouse quantity is only in OITW.
  • Invalid column name 'IsCommitted': SAP B1 spells the committed-quantity column IsCommited, with a single t. Use T0.IsCommited.
  • Available looks too high for urgent orders: Available adds OnOrder, which includes purchase orders that may arrive weeks later. Use OnHand - IsCommited for what can ship today.
  • Service items are not in the list: Only inventory items have rows in OITW. Non-stock and service items never appear, which is expected.

Need this report built into SAP Business One?

A saved query answers the question once. We build SAP Business One mobile apps: warehouse scanning, stock counts, sales orders and approvals on the Service Layer. Or hire a SAP Business One developer for the whole job, fixed price per phase.

Inventory

Related queries

Table reference: OITW table (Item stock per warehouse) · OITM table (Items (item master data))

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 stock by warehouse 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 OITW, OITM 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.