Start a project

Last purchase price per item

The most recent A/P invoice price, vendor and date for every item.

Tables: OPCH, PCH1Use: Price checks before new purchase orders.

Tool

SELECT X.ItemCode, X.Dscription, X.Price, X.Currency, X.CardName, X.DocDate
FROM (
  SELECT T1.ItemCode, T1.Dscription, T1.Price, T1.Currency, T0.CardName, T0.DocDate,
    ROW_NUMBER() OVER (PARTITION BY T1.ItemCode ORDER BY T0.DocDate DESC, T0.DocEntry DESC) AS RowNo
  FROM OPCH T0
  INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry
  WHERE T0.CANCELED = 'N'
) X
WHERE X.RowNo = 1
ORDER BY X.ItemCode
Need your UDFs in this report, or a dashboard? We extend it for your company.Customize it →

What this query answers

Before approving a new purchase order, the purchasing manager wants to see what was paid last time for each item, to whom and when. It catches price increases that a supplier did not announce.

Sample output

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

ItemCodeDscriptionPriceCurrencyCardNameDocDate
A00001Laser Printer 1420410USDGlobal Parts Co.2026-09-14
A00005Toner Cartridge Black27.5USDGlobal Parts Co.2026-10-02
A00007Paper A4 Box6.9EURMetro Packaging2026-08-21
A00009USB Cable 2m2.4USDGlobal Parts Co.2026-07-30

SQL Server vs SAP HANA

ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...) is supported the same way on HANA, so the window function is untouched. The only change is quoting, including the inner alias "RowNo" that the outer WHERE filters on.

Common errors and fixes

  • Prices in different currencies are compared side by side: Price is in the invoice line currency shown in the Currency column. Compare only rows with the same currency, or use T1.LineTotal / T1.Quantity for a local-currency unit price.
  • Items that were bought recently are missing: Only A/P invoices (OPCH) are read. If goods are received with a Goods Receipt PO and invoiced later, read OPDN/PDN1 instead or add them with UNION ALL.
  • The price is lower than the supplier's price list: PCH1.Price is the unit price after the line discount. Select T1.PriceBefDi as well to see the price before discount.

Need this report built into SAP Business One?

A saved query answers the question once. We build SAP Business One vendor portals: vendors confirm purchase orders and delivery dates, upload invoices as A/P drafts and check payment status. Or hire a remote SAP Business One developer for the whole job, fixed price per phase.

Purchasing

Related queries

Table reference: OPCH table (A/P Invoice (header)) · PCH1 table (A/P Invoice (rows))

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 last purchase price per item 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, PCH1 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.