Sub topic 8
Following a procure-to-pay chain from PO to invoice
This chapter assumes you can open documents in the SAP GUI and read tables in SE16N. It also assumes you know the basic Materials Management (MM) and Financial Accounting (FI) roles in a purchase. The code section needs basic ABAP SELECT syntax.
Why procure-to-pay has no VBFA
In sales, one table (VBFA) links every follow-on document. Purchasing does not work this way. The links in a purchase chain are spread across several places:
- The purchase order (PO) keeps its own history in table EKBE.
- Each follow-on document keeps a reference back to the PO.
- The accounting document stores a reference to the logistics document that caused it.
So you follow a procure-to-pay chain by reading the PO history first. From there you jump to each document it lists. The chain crosses MM (purchase order, goods receipt, invoice verification) and FI (the postings those steps create).
The documents in the chain
| Step | Business event | Document | Typical transaction | Header and item tables |
|---|---|---|---|---|
| 1 | Order goods | Purchase order | ME21N, ME23N | EKKO, EKPO |
| 2 | Receive goods | Material document | MIGO, MB03 | MKPF, MSEG (MATDOC in S/4HANA) |
| 3 | Post the vendor invoice | Logistics invoice document | MIRO, MIR4 | RBKP, RSEG |
| 4 | Account for the posting | Accounting document | FB03 | BKPF, BSEG |
Steps 2 and 3 each create an accounting document too. A goods receipt that is valued posts to inventory and the goods receipt/invoice receipt (GR/IR) clearing account. The invoice posts against GR/IR and the vendor account. This gives three-way matching: the PO, the goods receipt and the invoice must agree on quantity and price.
PO history: the central link table
EKBE is the purchasing document history. Each row records one event on one PO item. The key fields are:
| Field | Meaning |
|---|---|
| EBELN, EBELP | PO number and item |
| ZEKKN | Account assignment sequence number, relevant for multiple account assignment |
| VGABE | Transaction or event type |
| GJAHR, BELNR, BUZEI | Fiscal year, number and item of the follow-on document |
| BEWTP | PO history category |
| SHKZG | Debit or credit indicator: `S` for debit, `H` for credit |
| MENGE | Quantity |
| DMBTR, WRBTR | Amount in local currency and in document currency |
The VGABE values that matter here are 1 for goods receipt, 2 for invoice receipt and 3 for subsequent debit or credit. Other values exist for items such as delivery costs.
BELNR and GJAHR identify different documents depending on VGABE:
- For a goods receipt row, they hold the material document number and year.
- For an invoice row, they hold the logistics invoice document number and year, not the FI document number.
This is the most common mistake in this chain. Do not look up an EKBE BELNR in BKPF directly. It is a logistics document number.
Reading it in the GUI
Open the PO in ME23N, select an item, and go to the Purchase Order History tab. It lists each goods receipt and invoice receipt with date, quantity and amount. Double-clicking a row opens the underlying document.
For a cross-PO overview, use ME2N or ME80FN. These read the same EKBE data and show which POs have receipts but no invoice, or the reverse.
From the invoice to the accounting document
Step 3 gives you a logistics invoice document, for example in MIR4. The accounting document is a separate object. You find it two ways.
In the GUI, open the invoice in MIR4 and use the Follow-On Documents function. It lists the accounting document, which you can open in FB03.
In a table, use the reference fields in BKPF:
| BKPF field | Meaning |
|---|---|
| AWTYP | Reference transaction, the type of source document |
| AWKEY | Reference key, identifying the source document |
| AWSYS | Logical system of the source, usually blank in a single system |
For an invoice from MIRO, AWTYP is RMRP. AWKEY is the invoice document number (10 digits) followed directly by the fiscal year (4 digits). Invoice 5105600123 in 2026 gives 51056001232026.
For a goods receipt, AWTYP is MKPF and AWKEY is built the same way: material document number plus material document year.
Tracing the chain with ABAP
The report below takes a PO number and reads its invoice history from EKBE. It then finds the accounting document for each invoice through AWTYP = 'RMRP' and the AWKEY built from invoice number and year.
REPORT zp2p_trace.
PARAMETERS p_ebeln TYPE ebeln OBLIGATORY.
START-OF-SELECTION.
SELECT ebelp, vgabe, gjahr, belnr, buzei, menge, shkzg
FROM ekbe
WHERE ebeln = @p_ebeln
ORDER BY ebelp, vgabe, gjahr, belnr, buzei
INTO TABLE @DATA(lt_hist).
IF lt_hist IS INITIAL.
WRITE: / 'No PO history found for', p_ebeln.
RETURN.
ENDIF.
LOOP AT lt_hist INTO DATA(ls_hist) WHERE vgabe = '2'.
DATA(lv_awkey) = CONV awkey( |{ ls_hist-belnr }{ ls_hist-gjahr }| ).
SELECT bukrs, belnr, gjahr
FROM bkpf
WHERE awtyp = 'RMRP'
AND awkey = @lv_awkey
INTO TABLE @DATA(lt_fi).
IF lt_fi IS INITIAL.
WRITE: / 'PO item', ls_hist-ebelp, 'invoice', ls_hist-belnr,
ls_hist-gjahr, '- no FI document found'.
ELSE.
LOOP AT lt_fi INTO DATA(ls_fi).
WRITE: / 'PO item', ls_hist-ebelp, 'invoice', ls_hist-belnr,
ls_hist-gjahr, '-> FI', ls_fi-bukrs, ls_fi-belnr,
ls_fi-gjahr.
ENDLOOP.
ENDIF.
ENDLOOP.To trace goods receipts, filter on vgabe = '1' and use AWTYP = 'MKPF' instead. The PO-to-goods-receipt link is the EKBE row itself, so no further lookup is needed to reach the material document.
Worked trace
Suppose PO 4500000123 has one item for 100 pieces.
- EKBE shows a row with
VGABE = 1,MENGE = 60,SHKZG = 'S'. This is a partial goods receipt.BELNRis the material document. - A second
VGABE = 1row shows the remaining 40 pieces. - A row with
VGABE = 2,MENGE = 100,SHKZG = 'S'shows the invoice.BELNRis the logistics invoice document. - Convert that
BELNRandGJAHRinto anAWKEYand search BKPF withAWTYP = 'RMRP'. The result is the FI document on the vendor account.
A cancelled goods receipt adds a VGABE = 1 row with SHKZG = 'H' for the reversed quantity. Net received quantity is the sum of S rows minus the sum of H rows. The later chapter on reversals covers this in detail.
Edge cases to expect
- Invoice without goods receipt. If the PO item is not flagged for goods-receipt-based invoice verification, an invoice can post before any receipt. EKBE then has a
VGABE = 2row with noVGABE = 1row. - Subsequent debit or credit. A later price correction creates a
VGABE = 3row. It does not change the original invoice row. - Several account assignments. The same item can have rows with different
ZEKKNvalues, so includeZEKKNwhen you need a unique key. - Non-valuated receipts. A goods receipt for non-valuated material still creates a material document and an EKBE row, but it may create no accounting document.
- Service POs. Service entry sheets appear in the PO history as well, so a service item's chain has an extra document between the PO and the invoice.
Exercise
A colleague takes BELNR from an EKBE row with VGABE = 2 and searches BKPF for it with BELNR = <that value>. The search returns nothing, or an unrelated document. What is wrong, and what should they search with instead?
Show answer
In an invoice row of EKBE, BELNR and GJAHR identify the logistics invoice document (RBKP), not the FI document. The FI document is found through the reference fields. Search BKPF with AWTYP = 'RMRP' and AWKEY equal to the invoice number followed by the fiscal year (14 characters).
Exercise
PO item 10 shows these EKBE rows: VGABE 1, MENGE 100, SHKZG S; VGABE 1, MENGE 100, SHKZG H; VGABE 1, MENGE 80, SHKZG S. What quantity has been received net?
Show answer
80. The first receipt of 100 was reversed by the H row of 100, and a new receipt of 80 was posted afterward. Net received is (100 + 80) minus 100 = 80.