Sub topic 15
Tracing a transaction through document flow
This chapter assumes you know the order-to-cash steps from the earlier chapters. It also assumes you can read basic ABAP Open SQL. Here you will follow one order from sales order to journal entry, first in the UI and then in the tables.
What document flow is
Document flow is the chain of links between the documents of one business transaction. Each link joins a preceding document to its successor, for example a sales order to its delivery. In the UI, open the sales order and choose Display Document Flow (the exact button label depends on the transaction). In the database, the links are stored in table VBFA.
Reading VBFA
Each VBFA row describes one link. The main fields are:
| Field | Meaning |
|---|---|
| VBELV, POSNV | Preceding document and item |
| VBELN, POSNN | Subsequent document and item |
| VBTYP_N | Category of the subsequent document |
Common VBTYP_N values are J for a delivery, R for a goods movement, M for an invoice and O for a credit memo. The query below reads the direct successors of one order. Run it inside a report or method.
DATA(lv_vbeln) = CONV vbeln_va( '0000012345' ).
SELECT vbelv, posnv, vbeln, posnn, vbtyp_n
FROM vbfa
WHERE vbelv = @lv_vbeln
INTO TABLE @DATA(lt_flow).VBFA stores only direct links. To reach the invoice, take the delivery numbers from this result and query VBFA again with each one as vbelv. Repeat until no rows come back.
Crossing into accounting
The billing document is the last SD document in the chain. Its accounting entry is found through the reference fields of the Universal Journal, table ACDOCA, not through VBFA. The reference type VBRK marks billing documents.
DATA(lv_billing) = CONV vbeln_vf( '0090001234' ).
SELECT rbukrs, gjahr, belnr, docln, racct, hsl
FROM acdoca
WHERE rldnr = '0L'
AND awtyp = 'VBRK'
AND awref = @lv_billing
INTO TABLE @DATA(lt_journal).You should see the receivable line and the revenue lines produced by billing. Compare their amounts with the billing document.
Common errors
- Querying only one level. A query on the order returns deliveries, not invoices. Follow the chain step by step.
- Mixing up number ranges. A delivery number and an order number can look alike. Always filter on both the document number and the category.
- Ignoring cancellations. A cancelled invoice still appears in the flow, next to its cancellation document. Check the category before you add up amounts.
- Forgetting the ledger filter. Without
rldnr = '0L', ACDOCA returns one row set per ledger, and your totals double.
Exercise
A sales order has VBFA rows pointing to delivery 0080005555 (category J). You need the billing document for that order. Which query do you run next, and why?
Show answer
Query VBFA again with vbelv = '0080005555'. VBFA stores only direct successors, so the delivery's own successors, such as the goods issue (R) and the invoice (M), are in rows where the delivery is the preceding document.