Sub topic 6
Following an order-to-cash chain from order to payment posting
This chapter assumes you can navigate the SAP GUI and read tables in SE16 or SE16N. It also assumes you know what SD, MM and FI cover and what the header and item structure of a business document looks like. The ABAP sections need only basic SELECT syntax.
By the end you will be able to follow one customer order through delivery, goods issue, billing, the accounting document and the incoming payment. You will know which table stores each hop and where the stored links stop.
The chain at a glance
Order-to-cash is the process that starts when a customer orders and ends when the customer's payment clears the receivable. It crosses three modules. SD creates the order, delivery and billing document. MM posts the goods issue. FI posts the receivable and the payment.
Each step references the one before it, and that reference is the document flow. The links are not stored in one place.
Three kinds of link appear here:
- SD-to-SD links (order, delivery, billing) sit in VBFA.
- The goods issue is also recorded in VBFA, and the material document it points to belongs to MM.
- The accounting document is not reached through VBFA in your own queries. You find it through the reference fields in BKPF, or through the billing header.
- The payment is a pure FI link, through clearing fields on the customer line item.
Step 1: Order to delivery
The sales order (transaction VA01, header table VBAK, item table VBAP) has document category C. When you create an outbound delivery with reference to it (VL01N), SAP writes a VBFA record that says "order item 10 is followed by delivery item 10". The delivery has category J, header table LIKP and item table LIPS.
If the order has several schedule lines or items, one delivery can cover some or all of them. The link is therefore stored per item, not per document.
Step 2: Delivery to goods issue
Posting goods issue (VL02N, or VL06G) creates a material document in MM. SAP adds a VBFA row whose preceding document is the delivery and whose subsequent document is the material document number. Its category is R, goods movement. The material document needs its year to be unique, so the VBFA row also carries a year field. Always read the number and the year together.
Goods issue also posts accounting entries: stock goes down and cost of goods sold goes up. These belong to the goods movement, not to the invoice. The chain therefore holds two accounting documents, which readers often confuse.
- The goods-issue accounting document refers to the material document.
- The billing accounting document refers to the billing document.
Step 3: Delivery to billing document
Billing (VF01) with reference to the delivery creates the billing document, category M, header table VBRK and item table VBRP. VBFA stores one link per billed item. A billing document can combine items from several deliveries, and one delivery can be billed in several invoices when it is billed partially.
Step 4: Billing document to accounting document
When the billing document is released to accounting, FI creates the receivable posting. Two stores identify the pair:
- The billing header VBRK holds the accounting document number in its
BELNRfield (and the related fiscal year and company code). If you already have the billing header, this is the quickest route. - The accounting header BKPF holds the reference back:
AWTYP = 'VBRK'names the originating transaction, andAWKEYholds the billing document number.
Querying BKPF is the dependable route when you start from FI, or when you work through the chain with a generic program. The AWKEY value is a character field of up to 20 positions, so convert the billing number with CONV awkey( ... ) rather than comparing it to a shorter type.
A billing document that is blocked for accounting has no accounting document yet. It shows in the flow only up to the billing document. Chapter material on troubleshooting covers this later.
Step 5: Accounting document to payment
The SD document flow display in a standard system ends at the accounting document. It does not follow the receivable into the customer's payment.
To follow the money, switch to FI. An incoming payment (F-28, or an automatic payment program run) clears the open receivable and creates a clearing document. Open customer items live in BSID. Cleared items move to BSAD, where AUGBL holds the clearing document number and AUGDT the clearing date. You match your invoice's accounting document to the BSAD row using company code, fiscal year and document number.
A partial payment leaves the invoice item open and creates a separate open item for the payment on account or residual, depending on configuration. Treat "no BSAD row" as "not fully cleared", not as an error.
Reading the chain in the GUI
Open the order in VA03 and choose Environment, Display Document Flow. The list shows each document with its category description, date and status. You can double-click a line to open the document.
Check these things as you read:
- Each delivery, billing document and material document appears under the document it follows.
- The accounting document appears under the billing document.
- Status text such as "Being processed" or "Completed" tells you whether an item is fully handled.
The GUI view is a rendering of VBFA plus a few extra lookups. Everything it shows can be rebuilt with queries, which the next section does.
Rebuilding the chain with ABAP
This report starts from a sales order, walks VBFA level by level to collect the follow-on documents, then looks up the accounting document for every billing document it found. Copy it into a Z program in a test system.
REPORT zotc_trace.
PARAMETERS p_vbeln TYPE vbeln_va OBLIGATORY.
TYPES: BEGIN OF ty_link,
vbelv TYPE vbfa-vbelv,
posnv TYPE vbfa-posnv,
vbeln TYPE vbfa-vbeln,
posnn TYPE vbfa-posnn,
vbtyp_n TYPE vbfa-vbtyp_n,
END OF ty_link.
DATA lt_all TYPE STANDARD TABLE OF ty_link WITH EMPTY KEY.
DATA lt_front TYPE STANDARD TABLE OF vbfa-vbelv WITH EMPTY KEY.
lt_front = VALUE #( ( p_vbeln ) ).
DO 6 TIMES.
IF lt_front IS INITIAL.
EXIT.
ENDIF.
SELECT vbelv, posnv, vbeln, posnn, vbtyp_n
FROM vbfa
FOR ALL ENTRIES IN @lt_front
WHERE vbelv = @lt_front-table_line
INTO TABLE @DATA(lt_step).
APPEND LINES OF lt_step TO lt_all.
CLEAR lt_front.
LOOP AT lt_step INTO DATA(ls_step).
APPEND ls_step-vbeln TO lt_front.
ENDLOOP.
SORT lt_front.
DELETE ADJACENT DUPLICATES FROM lt_front.
ENDDO.
LOOP AT lt_all INTO DATA(ls_link).
WRITE: / ls_link-vbelv, ls_link-posnv, '->',
ls_link-vbeln, ls_link-posnn, ls_link-vbtyp_n.
IF ls_link-vbtyp_n = 'M'.
DATA(lv_awkey) = CONV awkey( ls_link-vbeln ).
SELECT bukrs, belnr, gjahr
FROM bkpf
WHERE awtyp = 'VBRK'
AND awkey = @lv_awkey
INTO TABLE @DATA(lt_fi).
LOOP AT lt_fi INTO DATA(ls_fi).
WRITE: / ' FI document', ls_fi-bukrs, ls_fi-belnr, ls_fi-gjahr.
ENDLOOP.
ENDIF.
ENDLOOP.Points to note about this program:
- The depth limit of 6 is a guard. The order-to-cash chain is normally four or five levels deep.
FOR ALL ENTRIESremoves duplicate result rows, which is harmless here. The program guards against an empty driver table, because an empty table would select every row in VBFA.- Rows with category
Rhave a material document number asVBELN. VBFA holds nothing that starts from that number, so the walk ends there. That is the expected behavior. - Billing documents that are cancelled have a different category and show up in the same list. Chapter material on reversals covers how to read them.
Once you have the accounting document number, add a final lookup to find whether the receivable is cleared:
SELECT bukrs, kunnr, gjahr, belnr, buzei, augbl, augdt
FROM bsad
WHERE bukrs = @ls_fi-bukrs
AND gjahr = @ls_fi-gjahr
AND belnr = @ls_fi-belnr
INTO TABLE @DATA(lt_cleared).An empty result means the item is still open (look in BSID) or the invoice has not been posted to FI.
What the chain looks like in the tables
| Hop | Preceding document | Subsequent document | Where the link is stored |
|---|---|---|---|
| Order to delivery | Sales order (C) | Delivery (J) | VBFA |
| Delivery to goods issue | Delivery (J) | Material document (R) | VBFA, plus the MM document itself |
| Delivery to billing | Delivery (J) | Billing document (M) | VBFA |
| Billing to accounting | Billing document | FI document | BKPF `AWTYP` and `AWKEY`, and VBRK `BELNR` |
| Accounting to payment | Receivable item | Clearing document | BSAD `AUGBL` |
Common mistakes
- Searching VBFA for the payment. VBFA does not hold payments. Use the customer line items.
- Ignoring the item number. Link rows are per item. Filtering on the header number alone merges unrelated items, and a delivery that covers only part of the order looks complete.
- Dropping the fiscal year. Accounting documents and material documents repeat their numbers across years. A lookup that leaves out the year can return the wrong document.
- Assuming one order gives one invoice. Partial deliveries and split billing produce several branches below one order.
Exercise
A sales order has one delivery, which was billed in two separate invoices. You query VBFA for the delivery number and get two rows with category M. Name two further lookups that complete the trace to the cash receipt for each invoice, and the keys you need for them.
Show answer
First, for each billing document, query BKPF with AWTYP = 'VBRK' and AWKEY set to that billing document number (or read BELNR from VBRK). This returns the company code, accounting document number and fiscal year. Second, query BSAD (cleared items) with that company code, fiscal year and accounting document number. A row returns the clearing document in AUGBL and the clearing date in AUGDT. If there is no BSAD row, look in BSID, where the item is still open.
Exercise
Why does the walk in the report stop at the goods issue, and what would you query to see the stock posting?
Show answer
The goods issue row in VBFA has category R, and its subsequent document is a material document number. VBFA holds no rows that start from a material document, so the walk ends. To see the stock and cost postings, read the material document in MM (MKPF and MSEG, or the material document view in S/4HANA) using the number and year from the VBFA row. Then find its accounting document through the reference fields in BKPF for goods movements.