Sub topic 2
What document flow is and why it exists
This chapter assumes you can navigate the SAP GUI, know what SD, MM and FI cover, and understand header and item structure. You should also be able to read a table in SE16 or SE16N. The ABAP section needs only basic SELECT syntax.
The problem document flow solves
A single business transaction rarely produces a single document. A customer order can lead to a sales order, a delivery, a goods issue material document, a billing document and an accounting document. Each document is created by a different application component and is stored in its own tables, with its own number range.
Without a link between them, you could not answer basic questions:
- Which delivery fulfilled this order item?
- Which invoice billed this delivery?
- Which accounting document recorded this invoice?
Document flow is the set of reference links that answers these questions. Each link says that document B was created with reference to document A. Following the links forward or backward gives you the chain of documents that belong to one business process.
A link is a reference, not a copy
A follow-on document does not contain a copy of its predecessor. It stores the predecessor's key, and some data is copied once at creation time. After that the two documents are independent records, and the link is the only thing that ties them together.
The link works at item level as well as header level. Delivery item 10 can point to order item 10, while order item 20 points to a different delivery altogether. This is why document flow is a graph and not a simple list. Later chapters on item-level links and partial processing cover this in detail.
A link normally carries three kinds of information:
- Predecessor key: the document number and item number of the earlier document.
- Successor key: the document number and item number of the later document.
- Category of each side: a code that says what kind of document it is, such as order, delivery or invoice. The next chapter covers these codes.
Links in the sales area also carry the quantity and value that the successor consumed from the predecessor. This is what lets SAP tell a fully delivered order item from a partly delivered one.
Where the links live
There is no single global "document flow table" for all of SAP. Each area stores links in the way that suits its processing, and the GUI display assembles them into one picture. You will meet three storage patterns in this tutorial.
| Area | Where the link is stored | What it links |
|---|---|---|
| Sales and distribution | Table `VBFA`, plus reference fields in the follow-on item tables, such as `VGBEL` and `VGPOS` in `LIPS` and `VBRP` | Inquiry, quotation, order, delivery, billing document, returns |
| Purchasing | Table `EKBE` (purchase order history) | Purchase order item to goods receipts, invoice receipts, subsequent debits and credits |
| Accounting | Reference fields in `BKPF`: `AWTYP` (reference transaction) and `AWKEY` (reference key) | Accounting document back to the source document that created it |
Two points are worth remembering:
- Because the follow-on item stores its predecessor's key, a link often exists in two places.
VBFAholds the link for navigation and quantity tracking, and the follow-on item holds its own reference. - The accounting link points in one direction only.
BKPFknows its source, but the source document does not list its accounting documents in a flow table. You find them by searchingBKPFon the reference fields, or from a field such asVBRK-BELNRfor billing documents.
Why SAP stores the links
Traceability for users and auditors is the visible benefit, but the links also drive processing logic.
- Status updates. When a delivery is created for an order item, SAP updates the order item's delivery status. It finds the related documents through the links and the quantities they record.
- Quantity control. The system uses the consumed quantities to know how much of an order item is still open for delivery or billing. This is how it prevents you from invoicing more than was delivered when billing is delivery-related.
- Copy control. Whether a delivery may follow a given order type, and which fields are copied, is configured per document pair. The links record which pair was actually used.
- Reversals and returns. A cancellation or a return needs to find the original document and reduce or restore the quantities it affected.
- Reporting. Open-item and backlog reports, such as orders not yet billed, depend on following the links.
- Troubleshooting. When a process stalls, the flow shows the last document that was successfully created.
The shape of a typical chain
The diagram shows a standard order-to-cash chain. Each arrow is a reference link, and the box text names the module that owns the document.
Note that the billing document follows the delivery, not the goods issue. In many configurations billing is delivery-related. The goods issue is a result of the delivery, and it can be posted before or after billing is created, depending on process design.
Forward and backward navigation
The same link can be read in two directions. In the sales flow, VBFA stores the predecessor in VBELV and POSNV and the successor in VBELN and POSNN.
- To go forward, filter on the predecessor columns and read the successor columns.
- To go backward, filter on the successor columns and read the predecessor columns.
The following report reads backward from a delivery. It lists the documents that the delivery was created from.
REPORT z_flow_backward.
DATA lv_delivery TYPE vbeln_vl VALUE '0080000321'.
SELECT vbelv, posnv, vbtyp_v, vbeln, posnn, vbtyp_n
FROM vbfa
WHERE vbeln = @lv_delivery
INTO TABLE @DATA(lt_predecessors).
IF sy-subrc <> 0.
cl_demo_output=>display( |No predecessor links found for { lv_delivery }| ).
ELSE.
cl_demo_output=>display( lt_predecessors ).
ENDIF.For a delivery created from a sales order, you would expect rows where VBELV is the order number and VBTYP_V marks it as an order. VBTYP_N marks the delivery. Replace the document number with one that exists in your system. The programmatic chapter returns to this with more complete queries.
Edge cases to keep in mind
One document can have many links. One order item can be split across several deliveries. Several order items can be combined into a single delivery or invoice. Expect one-to-many and many-to-one shapes, and never assume that a document has exactly one successor.
The flow is not the same as the status. The overall processing status of a document is a field on the document. It is derived from the links, but it is stored separately. A status can look wrong while the links are fine, and the reverse can happen too.
Links can be incomplete. Documents created by data migration, custom programs that write tables directly, or interfaces that skip the standard function modules may have missing or partial links. The document exists, but the flow display does not show it. A later chapter on troubleshooting covers diagnosis.
Some references are not flow links. A document may carry a purchase order number typed in by the customer, or an external reference text. This is plain data. It does not create a link, and it does not appear in the flow.
Links outlive the need to display them. Archiving can remove documents while their neighbours remain. A flow can then show a predecessor that you can no longer open.
What comes next
The next chapter covers document categories and types, which are the codes that label each side of a link. After that, you will read the flow in the GUI and then look at VBFA in detail.
Exercise
A delivery was created from a sales order. You need to find the sales order, starting from the delivery number. Which columns of VBFA do you filter on and which do you read? Also, why can the same query return more than one row?
Show answer
Filter on the successor columns, VBELN (and POSNN for a specific item) equal to the delivery number. Read the predecessor columns VBELV and POSNV, with VBTYP_V to confirm the category. More than one row can come back because the delivery has several items, each linked to its own order item, and one delivery can combine items from more than one order.
Exercise
A billing document exists, but you cannot find its accounting document in a flow table. Where do you look, and why does the link behave differently from the order-to-delivery link?
Show answer
Search BKPF with AWTYP = 'VBRK' and AWKEY equal to the billing document number, or read VBRK-BELNR. The accounting document stores a reference back to its source through the reference fields. The source document does not hold a list of its accounting documents in a flow table like VBFA.