Sub topic 1
Documents in SAP: headers, items and numbers
Prerequisites
This chapter assumes you can do the following:
- Navigate the SAP GUI and start transactions by code.
- Name the main modules: SD (Sales and Distribution), MM (Materials Management) and FI (Financial Accounting).
- Open a table in SE16 or SE16N and read its columns.
You do not need ABAP for this chapter. The one query shown is short and can be read without ABAP experience.
What a business document is
A business document is a record that SAP creates when a transaction happens. Examples are a sales order, a delivery, a purchase order, a material document, an invoice and an accounting document. Each document is stored in database tables, and each one gets its own number.
Document flow, the topic of this tutorial, links these records into a chain. Before you can follow a link, you need to know what is being linked. That is the header and item structure.
Headers and items
Almost every SAP document has two levels:
- The header holds data that applies to the whole document, such as the customer, the document date, the currency and the organizational unit.
- The items hold data for each line, such as the material, the quantity, the unit of measure and the price.
A sales order for three materials has one header and three items. Each item has an item number, usually 10, 20, 30 and so on. The gaps let users insert lines later without renumbering.
The header and item data sit in separate tables. The table below shows the main pairs you will meet in this tutorial.
| Document | Header table | Item table |
|---|---|---|
| Sales order | VBAK | VBAP |
| Delivery | LIKP | LIPS |
| Billing document | VBRK | VBRP |
| Purchase order | EKKO | EKPO |
| Material document | MKPF | MSEG |
| Accounting document | BKPF | BSEG |
In SAP S/4HANA, the item data of accounting documents is read through ACDOCA, and BSEG is no longer the main source. Chapter 15 covers that change.
Document numbers
A document number identifies one document inside its number range. SAP assigns it when the document is saved, from a number range linked to the document type. Three points matter for tracing:
- Numbers are stored with leading zeros. A sales order shown as 4711 in the GUI is stored as
0000004711. A query that compares against'4711'finds nothing. - Numbers are not unique across document types. Sales order 4711 and delivery 4711 can both exist. A number only identifies a document together with its type.
- Accounting documents need more than the number. The key is company code, document number and fiscal year. The same number can repeat in another company code or another year.
The item number is part of the key too. Item 10 of order 4711 is a different record from item 10 of order 4712.
Why the key matters for document flow
A link between two documents is a pair of keys. For example, a delivery item points back to the order item it came from. This works only if both keys are complete. Document number alone is not enough, and the header link alone does not say which items belong together.
The following query reads the header of one sales order. It shows the leading zeros in practice.
DATA lv_order TYPE vbeln_va VALUE '0000004711'.
SELECT SINGLE vbeln, auart, kunnr, erdat
FROM vbak
WHERE vbeln = @lv_order
INTO @DATA(ls_header).auart is the sales document type and kunnr is the customer number. The value of lv_order carries all ten digits.
Exercise
Order 4711 and delivery 4711 both exist in the system. Why does this not cause a conflict, and what do you need to identify a posted accounting document uniquely?
Show answer
Each document type has its own number range and its own tables, so the same number can appear in more than one type. An accounting document is identified by company code, document number and fiscal year.