Sub topic 9
How accounting documents point back to their source
This chapter assumes you know headers and items, can read tables in SE16, and understand the order-to-cash and procure-to-pay chains from earlier chapters. It covers how an FI document records which SD or MM document created it.
Why FI needs its own reference
Table VBFA links sales documents and EKBE links purchasing history. An accounting document is stored in a different way. FI does not keep a chain of links to its source. Each accounting document header carries a pointer back to the document that triggered it.
The header table is BKPF. Two fields in it hold the pointer:
- AWTYP is the reference transaction. It names the kind of source document, for example
VBRKfor a billing document orRMRPfor a supplier invoice from Invoice Verification. - AWKEY is the reference key. It holds the source document number. For some sources it also holds the fiscal year.
Together they form an object key. FI uses this key to jump back to the original document, for example when you display an accounting document and choose the related source document.
Finding the FI document for a billing document
Billing document 0090000123 posted to accounting. To find the FI document, match AWTYP and AWKEY.
DATA lv_awkey TYPE awkey VALUE '0090000123'.
SELECT bukrs, belnr, gjahr, awtyp, awkey
FROM bkpf
WHERE awtyp = 'VBRK'
AND awkey = @lv_awkey
INTO TABLE @DATA(lt_fi_docs).The result gives the company code (BUKRS), accounting document number (BELNR) and fiscal year (GJAHR). All three together identify the document, because BELNR is only unique within a company code and year.
Key formats differ by source
The format of AWKEY depends on AWTYP. The next table shows common cases.
| AWTYP | Source | AWKEY content |
|---|---|---|
| VBRK | Billing document | Billing document number |
| MKPF | Material document | Material document number plus material document year |
| RMRP | Logistics invoice verification | Invoice document number plus fiscal year |
The billing example works with a plain number. For MKPF and RMRP you must build the key with the year appended. A query that uses only the document number returns nothing, and this is a common mistake.
The two directions
The pointer runs from FI to the source. SD and MM can also reach FI. A billing document stores the accounting document number in VBRK (field BELNR) when it has posted. The pointer in BKPF is the reliable one, because it exists for every document type.
Use the diagram below to see the full direction of the links.
Common errors
- Searching BKPF by AWKEY alone. Always include AWTYP, since the same number can exist in two source tables.
- Ignoring the year in the key for material and invoice documents.
- Expecting one FI document per source. A single material document can create several accounting documents, for example when valuation areas differ.
- Treating BKPF as a link table. It records one source per accounting document, so follow-on payments such as incoming payments are linked through clearing fields, not through AWKEY.
Exercise
A billing document has number 0090000123. Your SELECT on BKPF with only AWKEY = '0090000123' returns two rows from different sources. What do you change, and why?
Show answer
Add AWTYP = 'VBRK' to the WHERE clause. The same key value can exist for different reference transactions, so AWTYP is needed to identify the source document type.