Sub topic 8
Following a procure-to-pay chain from PO to invoice
This chapter assumes you can navigate the SAP GUI, read tables in SE16N, and write a basic ABAP SELECT. You should also know what a document header and item are. The aim is to follow one purchase order (PO) through goods receipt and invoice receipt, and then to the accounting document.
The chain at a glance
Procure-to-pay starts in MM and ends in FI. Each step creates a new document that points back to the one before it.
The purchase order is the anchor. Goods receipt and invoice receipt both refer to it, so both appear in its history.
Where the links live
Sales documents store their links in VBFA. Purchasing works differently. The links are kept in the PO history table EKBE, with one row for each follow-on posting against a PO item.
Key fields in EKBE:
| Field | Meaning |
|---|---|
| EBELN, EBELP | PO number and item |
| VGABE | Transaction type: 1 goods receipt, 2 invoice receipt, 3 subsequent debit or credit |
| GJAHR, BELNR, BUZEI | Fiscal year, document number and item of the follow-on document |
| MENGE | Quantity posted |
For VGABE 1, BELNR is a material document. For VGABE 2, it is a logistics invoice document. The fiscal year is part of the key, so always read GJAHR together with BELNR.
Reading the history in the GUI
Open the PO in ME23N and select an item. The PO History tab lists the goods receipts and invoice receipts for that item. It is a view of EKBE. From there you can double-click a document to display it.
Reading the history with ABAP
DATA lv_po TYPE ebeln VALUE '4500000123'.
SELECT ebeln, ebelp, vgabe, gjahr, belnr, buzei, menge
FROM ekbe
WHERE ebeln = @lv_po
ORDER BY ebelp, vgabe, gjahr, belnr, buzei
INTO TABLE @DATA(lt_history).Each row in lt_history is one posting. Grouping by item and VGABE shows how much was received and how much was invoiced. If the invoiced quantity is higher than the received quantity, you will usually see a blocked invoice, which is covered in the troubleshooting chapter.
From invoice to accounting
A goods receipt or invoice receipt also posts an FI document. The material document or invoice number is not the FI document number. The FI header (BKPF) keeps a reference in AWTYP (the reference transaction) and AWKEY (the reference key). For a logistics invoice, AWTYP is RMRP, and AWKEY is the invoice number joined with the fiscal year. For a goods receipt, AWTYP is MKPF, and AWKEY is the material document number joined with the year.
DATA lv_awkey TYPE awkey VALUE '51050000012024'.
SELECT bukrs, belnr, gjahr, awtyp, awkey
FROM bkpf
WHERE awtyp = 'RMRP'
AND awkey = @lv_awkey
INTO TABLE @DATA(lt_fi_docs).The key above is an example: invoice number 5105000001 followed by fiscal year 2024.
Common mistakes
- Reading BELNR from EKBE without GJAHR, which can return the wrong document when numbers repeat across years.
- Treating every EKBE row as a goods receipt. Filter on VGABE.
- Expecting EKBE to hold the FI document number. It holds the MM document, and you must go through BKPF to reach FI.
- Summing MENGE without handling reversals, which appear as separate rows. The reversals chapter explains how to read them.
Exercise
A PO item shows two EKBE rows with VGABE = 1 and one row with VGABE = 2. Which documents do these rows point to, and how do you find the FI document for the invoice row?
Show answer
The two VGABE 1 rows point to material documents (goods receipts). The VGABE 2 row points to a logistics invoice document. To find its FI document, query BKPF with AWTYP = 'RMRP' and AWKEY set to the invoice number followed by the fiscal year from the EKBE row.