VBAK / VBAP — Sales Order Header and Line Items¶
VBAK holds one row per sales order; VBAP holds one row per order item. Always join on MANDT + VBELN.
Purpose¶
VBAK and VBAP are the core SD tables for sales orders (order type OR), quotations, contracts, and scheduling agreements. VBAK stores the header-level data — who ordered, which sales organisation, document currency, and total net value. VBAP holds the line items: which material, what quantity, which plant should deliver, and the net price.
Key fields¶
VBAK — Header¶
| Field | Type | Description |
|---|---|---|
| MANDT | CLNT(3) | Client |
| VBELN | CHAR(10) | Sales document number (leading zeros, e.g. 0000012345) |
| AUART | CHAR(4) | Sales document type (OR=standard order QT=quotation) |
| KUNNR | CHAR(10) | Sold-to customer number |
| VKORG | CHAR(4) | Sales organisation |
| VTWEG | CHAR(2) | Distribution channel |
| ERDAT | DATS(8) | Creation date |
| NETWR | CURR | Net order value in document currency |
| WAERK | CUKY(5) | Document currency |
VBAP — Item¶
| Field | Type | Description |
|---|---|---|
| MANDT | CLNT(3) | Client |
| VBELN | CHAR(10) | Sales document number (FK to VBAK) |
| POSNR | NUMC(6) | Item number (e.g. 000010) |
| MATNR | CHAR(18) | Material number |
| ARKTX | CHAR(40) | Short text / item description |
| KWMENG | QUAN | Cumulative order quantity (in sales unit) |
| VRKME | UNIT(3) | Sales unit |
| NETPR | CURR | Net price per sales unit |
| WERKS | CHAR(4) | Delivering plant |
| ABGRU | CHAR(2) | Rejection reason (blank = not rejected) |
Common queries¶
All open (non-rejected) line items for a customer
SELECT k~vbeln, k~auart, k~erdat,
p~posnr, p~matnr, p~arktx, p~kwmeng, p~vrkme, p~netpr
INTO TABLE @DATA(lt_items)
FROM vbak AS k
INNER JOIN vbap AS p ON p~mandt = k~mandt
AND p~vbeln = k~vbeln
WHERE k~mandt = @sy-mandt
AND k~kunnr = @lv_kunnr
AND k~auart = 'OR'
AND p~abgru = ''.
All line items for a single sales order
SELECT vbeln, posnr, matnr, arktx, kwmeng, vrkme, netpr, werks
INTO TABLE @DATA(lt_order_items)
FROM vbap
WHERE mandt = @sy-mandt
AND vbeln = @lv_vbeln
ORDER BY posnr.
Orders created this month with total value above a threshold
DATA(lv_month_start) = |{ sy-datum(6) }01|.
SELECT vbeln, auart, kunnr, erdat, netwr, waerk
INTO TABLE @DATA(lt_orders)
FROM vbak
WHERE mandt = @sy-mandt
AND auart = 'OR'
AND erdat >= @lv_month_start
AND netwr > @lv_min_value
ORDER BY netwr DESCENDING.
Joins¶
| Join target | Key fields | Purpose |
|---|---|---|
| VBAP | MANDT + VBELN |
Line items for the order |
| KNA1 | MANDT + KUNNR (from VBAK) |
Customer name and address |
| MARA/MAKT | MATNR (from VBAP) |
Material description |
| VBUP | MANDT + VBELN + POSNR |
Item completion / delivery status |
" Orders with customer name
SELECT k~vbeln, k~erdat, k~netwr, k~waerk,
c~name1 AS customer_name
INTO TABLE @DATA(lt_orders_named)
FROM vbak AS k
INNER JOIN kna1 AS c ON c~mandt = k~mandt
AND c~kunnr = k~kunnr
WHERE k~mandt = @sy-mandt
AND k~auart = 'OR'
AND k~erdat = @sy-datum.
Pitfalls¶
VBELN has leading zeros
Sales document numbers are stored as 10-character strings with leading zeros (0000012345). When accepting user input, pad with CONVERSION_EXIT_ALPHA_INPUT before querying, or the WHERE clause will return no results.
Rejected items remain in VBAP
A line item with a rejection reason in ABGRU is still physically present in VBAP. Always add AND p~abgru = '' (or handle non-blank values explicitly) when you want only active items.
Use VBUP for completion status
VBAK/VBAP do not have a single "order status" flag. Overall and item-level delivery and billing completion is tracked in VBUP (item level) and VBUK (header level). Do not infer open/closed status from VBAK alone.
See also¶
mara.md— Material master for MATNR lookupsbkpf-bseg.md— FI documents created when SD invoices are posted