SAP SD Document Flow Table (VBFA) ABAP Generator
This generator writes an ABAP report for SAP ECC 6.0 that traces the SD document flow of one sales document through VBFA, from order to delivery to invoice, goods movement, cancellation and credit memo. It adds the header and item processing status from VBUK and VBUP, which is where ECC keeps them.
Fill in
C order, H returns, K credit memo request, L debit memo request, J delivery.
J delivery, M invoice, R goods movement, N invoice cancellation, O credit memo, T returns delivery.
Declarations and selection screen
REPORT zsd_document_flow.
* Document flow for 0000012345 (category C), follow-ons JMRNO
* VBTYP: C order, J delivery, M invoice, N invoice cancellation,
* O credit memo, R goods movement, H returns, T returns delivery
TYPES: BEGIN OF ty_flow,
vbelv TYPE vbfa-vbelv,
posnv TYPE vbfa-posnv,
vbeln TYPE vbfa-vbeln,
posnn TYPE vbfa-posnn,
vbtyp_n TYPE vbfa-vbtyp_n,
vbtyp_v TYPE vbfa-vbtyp_v,
rfmng TYPE vbfa-rfmng,
meins TYPE vbfa-meins,
erdat TYPE vbfa-erdat,
END OF ty_flow.
DATA: gt_flow TYPE STANDARD TABLE OF ty_flow,
gt_deliv TYPE STANDARD TABLE OF ty_flow,
gs_flow TYPE ty_flow,
gr_vbtyp TYPE RANGE OF vbfa-vbtyp_n,
gs_vbtyp LIKE LINE OF gr_vbtyp,
gv_cats TYPE c LENGTH 20,
gv_len TYPE i,
gv_off TYPE i,
gs_vbuk TYPE vbuk,
gt_vbup TYPE STANDARD TABLE OF vbup,
gs_vbup TYPE vbup.
PARAMETERS: p_vbeln TYPE vbfa-vbelv DEFAULT '0000012345' OBLIGATORY,
p_vbtyp TYPE vbfa-vbtyp_v DEFAULT 'C' OBLIGATORY.Level 1 and level 2 flow from VBFA
START-OF-SELECTION.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = p_vbeln
IMPORTING
output = p_vbeln.
* Build a range of follow-on categories from the letters
gv_cats = 'JMRNO'.
gv_len = strlen( gv_cats ).
DO gv_len TIMES.
gv_off = sy-index - 1.
CLEAR gs_vbtyp.
gs_vbtyp-sign = 'I'.
gs_vbtyp-option = 'EQ'.
gs_vbtyp-low = gv_cats+gv_off(1).
APPEND gs_vbtyp TO gr_vbtyp.
ENDDO.
* Level 1: direct successors of the start document (uses the VBELV key)
SELECT vbelv posnv vbeln posnn vbtyp_n vbtyp_v rfmng meins erdat
FROM vbfa
INTO TABLE gt_flow
WHERE vbelv = p_vbeln
AND vbtyp_v = p_vbtyp
AND vbtyp_n IN gr_vbtyp.
* Level 2: successors of each delivery (invoices, goods movements)
SELECT vbelv posnv vbeln posnn vbtyp_n vbtyp_v rfmng meins erdat
FROM vbfa
INTO TABLE gt_deliv
WHERE vbelv = p_vbeln
AND vbtyp_v = p_vbtyp
AND vbtyp_n = 'J'.
SORT gt_deliv BY vbeln.
DELETE ADJACENT DUPLICATES FROM gt_deliv COMPARING vbeln.
IF gt_deliv IS NOT INITIAL.
SELECT vbelv posnv vbeln posnn vbtyp_n vbtyp_v rfmng meins erdat
FROM vbfa
APPENDING TABLE gt_flow
FOR ALL ENTRIES IN gt_deliv
WHERE vbelv = gt_deliv-vbeln
AND vbtyp_v = 'J'
AND vbtyp_n IN gr_vbtyp.
ENDIF.
SORT gt_flow BY vbelv posnv vbeln posnn vbtyp_n.
DELETE ADJACENT DUPLICATES FROM gt_flow
COMPARING vbelv posnv vbeln posnn vbtyp_n.Header status (VBUK), item status (VBUP) and output
SELECT SINGLE * FROM vbuk INTO gs_vbuk WHERE vbeln = p_vbeln.
SELECT * FROM vbup INTO TABLE gt_vbup WHERE vbeln = p_vbeln.
* Status values: space not relevant, A not processed,
* B partially processed, C completely processed
WRITE: / 'GBSTK', gs_vbuk-gbstk, 'LFSTK', gs_vbuk-lfstk,
'FKSTK', gs_vbuk-fkstk, 'WBSTK', gs_vbuk-wbstk,
'CMGST', gs_vbuk-cmgst.
LOOP AT gt_vbup INTO gs_vbup.
WRITE: / gs_vbup-posnr, 'LFSTA', gs_vbup-lfsta,
'FKSTA', gs_vbup-fksta, 'GBSTA', gs_vbup-gbsta,
'ABSTA', gs_vbup-absta.
ENDLOOP.
ULINE.
LOOP AT gt_flow INTO gs_flow.
WRITE: / gs_flow-vbelv, gs_flow-posnv, gs_flow-vbtyp_v, '->',
gs_flow-vbeln, gs_flow-posnn, gs_flow-vbtyp_n,
gs_flow-rfmng UNIT gs_flow-meins, gs_flow-meins,
gs_flow-erdat.
ENDLOOP.Status field decode
| Table-field | Meaning | A / B / C |
|---|---|---|
| VBUK-GBSTK | Overall processing status of the document | Open / in process / completed |
| VBUK-LFSTK | Delivery status (header) | Not delivered / partly / fully |
| VBUK-FKSTK | Billing status (header) | Not billed / partly / fully |
| VBUK-WBSTK | Total goods movement status | Not posted / partly / fully |
| VBUK-CMGST | Overall credit check status | A checked, OK / B checked, not OK (blocked) / C not OK, partly released; D released by credit representative |
| VBUP-LFSTA | Delivery status (item) | Not delivered / partly / fully |
| VBUP-FKSTA | Billing status (item) | Not billed / partly / fully |
| VBUP-GBSTA | Overall processing status (item) | Open / in process / completed |
| VBUP-ABSTA | Rejection status (item) | Not rejected / partly / fully rejected |
Alternative: standard function RV_ORDER_FLOW_INFORMATION
* Same information as the VA03 document flow screen, all levels.
DATA: gs_comwa TYPE vbco6,
gt_vbfa TYPE STANDARD TABLE OF vbfa.
gs_comwa-vbeln = p_vbeln.
CALL FUNCTION 'RV_ORDER_FLOW_INFORMATION'
EXPORTING
comwa = gs_comwa
nachfolger = 'X'
n_stufen = '50'
vorgaenger = ' '
TABLES
vbfa_tab = gt_vbfa
EXCEPTIONS
no_vbfa = 1
no_vbuk_found = 2
OTHERS = 3.Verify in SE11 that VBFA has VBELV, POSNV, VBELN, POSNN, VBTYP_N, VBTYP_V, RFMNG, MEINS and ERDAT on your release, and in SE37 that RV_ORDER_FLOW_INFORMATION has COMWA (VBCO6), NACHFOLGER, N_STUFEN, VORGAENGER and table VBFA_TAB. In S/4HANA VBUK and VBUP no longer hold the data: the status fields moved into VBAK/VBAP, LIKP/LIPS and VBRK/VBRP, so this status block will not port as is.
Want order-to-cash status as a ready report?
Tell us your document types and copy control and we will review the generated flow report against your ECC system and its custom indexes.
Optional. The tool and every export work without this. No spam.
Which tables make up SD document flow in ECC
VBFA is the document flow table: each row links a preceding document and item (VBELV, POSNV, category VBTYP_V) to a subsequent document and item (VBELN, POSNN, category VBTYP_N), with the referenced quantity RFMNG in unit MEINS and the creation date. Around it sit the document tables: VBAK and VBAP for sales documents, LIKP and LIPS for deliveries, VBRK and VBRP for billing, and MKPF and MSEG for the goods movement that VBFA lists as category R. Status is not on those tables in ECC: header status is in VBUK and item status in VBUP, both keyed by document number. Partners are in VBPA and schedule lines in VBEP.
- VBAK/VBAP to LIPS via LIPS-VGBEL and LIPS-VGPOS
- LIPS to VBRP via VBRP-VGBEL and VBRP-VGPOS; VBRP-AUBEL holds the order
- VBFA category R rows point to the material document number
- VBUK/VBUP: A not processed, B partly, C fully, blank not relevant
How the generated report reads the flow
VBFA's primary key starts with VBELV and POSNV, so reading forward from a known document is a fast key access. The report reads level 1 (everything the start document points to) and then level 2 from each delivery, because invoices and goods movements for delivery-related billing are recorded against the delivery. The follow-on categories you type become a range on VBTYP_N, so JMR gives deliveries, invoices and goods movements only. Duplicates from the two levels are removed. The header line prints GBSTK, LFSTK, FKSTK, WBSTK and CMGST; each item prints LFSTA, FKSTA, GBSTA and ABSTA. If you want every level and predecessors as VA03 shows them, the last block calls RV_ORDER_FLOW_INFORMATION instead.
Reading backward and performance
Going backward, for example from an invoice to its order, means filtering VBFA on VBELN, which is not the leading key field. Without a secondary index that is a full table scan on one of the largest SD tables. Better options: read VBRP-AUBEL and VBRP-VGBEL for the order and delivery behind an invoice item, or LIPS-VGBEL for the order behind a delivery item. Some systems have a customer index on VBFA-VBELN; check in SE11 before relying on it. Also restrict VBTYP_N: without it, a busy order with many partial deliveries and invoices can return hundreds of rows per item.
Version differences: ECC versus S/4HANA
This code targets ECC 6.0. In S/4HANA the status tables VBUK and VBUP are obsolete as data stores: the status fields were moved into the document header and item tables (for example VBAK and VBAP for sales documents, LIKP and LIPS for deliveries). VBFA itself remains but was simplified, so test any VBFA logic again after a conversion. Code that reads VBUK directly is one of the standard findings in the S/4HANA custom code check, so if a conversion is coming, wrap these reads in one method you can replace later.
Frequently Asked Questions
What is the SD document flow table in SAP?
VBFA is the sales document flow table. Each row links a preceding document and item (VBELV, POSNV) to a subsequent document and item (VBELN, POSNN), with the categories VBTYP_V and VBTYP_N, the referenced quantity RFMNG and its unit. VA03 Environment, Display document flow reads the same data.
What do the VBTYP values in VBFA mean?
Common values: C sales order, H returns, K credit memo request, L debit memo request, J delivery, T returns delivery, M invoice, N invoice cancellation, O credit memo, P debit memo and R goods movement. VBTYP_V is the category of the preceding document and VBTYP_N of the subsequent one. Check domain VBTYP in SE11 for the full list.
Which tables are used in SAP SD?
The core set is VBAK and VBAP (sales header and item), VBEP (schedule lines), VBPA (partners), LIKP and LIPS (deliveries), VBRK and VBRP (billing), VBFA (document flow) and, in ECC, VBUK and VBUP (header and item status). KNA1 and KNVV hold customer master data, and conditions are in KONV in ECC.
How do I find the invoice for a sales order without a slow VBFA query?
Read VBFA forward with VBELV = order number and VBTYP_N = M, which uses the key. If you only have the invoice and need the order, do not search VBFA on VBELN; read VBRP-AUBEL for the order and VBRP-VGBEL for the delivery instead, both on the invoice item.
If your order desk wants to ask where an order stands, delivered, billed or blocked, in plain English against ECC on your own servers, we can build that read-only AI layer over the same tables.
Related Tools
SAP ECC Order System Status ABAP Generator (JEST, TJ02T, STATUS_TEXT_EDIT)
Fill in plant, order type and the statuses to include and exclude, and get a working ABAP report that reads AUFK, JEST, TJ02T and TJ30T and prints the status line with STATUS_TEXT_EDIT.
Developer ToolsSAP ECC BAPI Mass Load Runtime and Commit Size Calculator
Enter records, measured milliseconds per BAPI call and per commit, records per commit and parallel tasks to estimate load runtime, compare with BDC and size error rework.
Developer ToolsSAP ECC BAdI Implementation Method Code Generator (ME_PROCESS_PO_CUST, MB_MIGO_BADI, WORKORDER_UPDATE)
Pick a plant, the field that must be filled and your message class, and get ready-to-paste method code for three common ECC classic BAdIs, with the SE19 steps.
Developer ToolsSAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
Fill in order type, sales area, customer, material and quantity to get an ABAP skeleton that creates a sales order through the standard BAPI.
More Developer Tools tools
See all- SAP ECC Enhancement Transactions and Exit Tables Reference (SMOD, CMOD, SE18, MODSAP, SXC_EXIT)
- SAP ECC Data Dictionary and Repository Tables Reference (DD02L, DD03L, T100, E070, TSTC)
- SAP ECC ABAP Runtime Errors (ST22 Dumps) and Error Log Transactions Reference
- SAP ECC Background Job History ABAP Query Generator (TBTCO + TBTCP)
- SAP ECC Background Job Creation ABAP Generator (JOB_OPEN, SUBMIT, JOB_CLOSE)
- SAP ECC IDoc Segment Data Reader ABAP Generator (EDIDC, EDID4, EDIDS)
- SAP ECC Custom Inbound IDoc Function Module Skeleton Generator
- SAP ECC BAPI_SALESORDER_CHANGE ABAP Generator
- SAP ECC BAPI_PO_CHANGE ABAP Generator
Keep exploring
Free tools
- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)Fill in sales organization, order type and date range to get a ready ABAP report skeleton that joins VBAK and VBAP and reads VBFA.
- SAP SD Sales Order Item ABAP SELECT GeneratorFill in the sales organization, order type and dates, and get a ready-to-adapt ABAP report that lists sales order items.
- SAP Sales Document Types ReferenceA searchable list of the standard SAP SD sales document types, with the SD document category and the way each one is normally used in a design.
Integrations
- How to use ChatGPT with SAP ECC 6.0Using ChatGPT with SAP ECC 6.0: custom GPT actions, exports versus live access, an OData or MCP bridge, enterprise data controls, and when a private model is safer.
- How to add document OCR to SAP ECC 6.0Capture invoices, packing slips and certificates into SAP ECC 6.0 with OCR and AI: ArchiveLink, parked invoices via BAPI, confidence thresholds and human review.