# Manufacturing Order Table in SAP: AUFK, AFKO, AFPO and RESB Join Generator

> Source: https://netray.co/tools/sap-manufacturing-order-tables-aufk-afko-afpo-resb-sql
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Generates SQL that joins the SAP production order header, item and component tables with the correct keys, plus a field guide to each table.

## Category

sap

## Erp

SAP ECC and S/4HANA

## Industry

Discrete Manufacturing

## Audience

- SAP developer
- PP consultant
- Report writer

## Tool

**Kind:** template

**Output:** code

**Language:** sql

**Fields:**

#### Client (MANDT)

**Key:** client

**Type:** text

**Default:** 100

#### Plant (WERKS)

**Key:** plant

**Type:** text

**Default:** 1000

#### Order type (AUART)

**Key:** order_type

**Type:** text

**Default:** PP01

#### Basic start date from (YYYYMMDD)

**Key:** date_from

**Type:** text

**Default:** 20260101

#### Basic start date to (YYYYMMDD)

**Key:** date_to

**Type:** text

**Default:** 20261231

**Blocks:**

#### Order header, quantity and material (AUFK, AFKO, AFPO)

**Body:** SELECT k.aufnr,
       k.auart,
       k.werks,
       k.ktext,
       h.gstrp  AS basic_start,
       h.gltrp  AS basic_finish,
       h.gamng  AS total_qty,
       p.matnr,
       p.psmng  AS planned_qty,
       p.wemng  AS delivered_qty,
       p.meins  AS uom
FROM   aufk k
       JOIN afko h
         ON h.mandt = k.mandt
        AND h.aufnr = k.aufnr
       JOIN afpo p
         ON p.mandt = k.mandt
        AND p.aufnr = k.aufnr
WHERE  k.mandt = '{{client}}'
  AND  k.werks = '{{plant}}'
  AND  k.auart = '{{order_type}}'
  AND  h.gstrp BETWEEN '{{date_from}}' AND '{{date_to}}'
  AND  k.loekz = ''
ORDER BY k.aufnr;

#### Add components (RESB through reservation number)

**Body:** SELECT k.aufnr,
       r.rspos,
       r.matnr  AS component,
       r.bdmng  AS required_qty,
       r.enmng  AS withdrawn_qty,
       r.meins  AS uom,
       r.lgort  AS storage_loc
FROM   aufk k
       JOIN afko h
         ON h.mandt = k.mandt
        AND h.aufnr = k.aufnr
       JOIN resb r
         ON r.mandt = h.mandt
        AND r.rsnum = h.rsnum
        AND r.aufnr = h.aufnr
WHERE  k.mandt = '{{client}}'
  AND  k.werks = '{{plant}}'
  AND  k.auart = '{{order_type}}'
  AND  h.gstrp BETWEEN '{{date_from}}' AND '{{date_to}}'
  AND  r.xloek = ''
ORDER BY k.aufnr, r.rspos;

#### Add operations (AFVC through order routing number)

**Body:** SELECT h.aufnr,
       v.vornr  AS operation,
       v.arbid  AS work_center_id,
       v.steus  AS control_key,
       v.ltxa1  AS op_text
FROM   afko h
       JOIN afvc v
         ON v.mandt = h.mandt
        AND v.aufpl = h.aufpl
WHERE  h.mandt = '{{client}}'
  AND  h.aufnr = :aufnr
ORDER BY v.vornr;

**Notes:** Field names are standard ECC and S/4HANA names but check them in SE11 for your release. In ECC use the SAP system's own SQL tools or ABAP Open SQL, since direct database access may be restricted. AUFK covers all order categories, so filter AUTYP = 10 for production orders and AUTYP = 40 for process orders when you need to separate them.

## Content

**Intro:** In SAP, a manufacturing (production) order is not stored in one table. The header is split across AUFK and AFKO, items sit in AFPO, components in RESB and operations in AFVC. This generator builds the joins with the correct keys.

**Sections:**

#### How to use the generator

**Body:** Enter client, plant, order type and a date range, then copy the SQL into your SQL tool or adapt it to Open SQL in an ABAP report or a CDS view. The first block gives order, material and quantity. The second adds components through the reservation number, and the third adds operations through the routing number. Run the first block alone while testing, to confirm row counts match what you see in COOIS.

#### What each table holds

**Body:** AUFK is the order master shared by all order categories, with order number, type, plant, company code, description, object number and status link. AFKO is the production order header with scheduling dates, total quantity, MRP controller, production supervisor and the keys AUFPL (routing number) and RSNUM (reservation number). AFPO holds the order items with material, planned and delivered quantity and unit. RESB holds the component requirements, and AFVC the operations.

**Bullets:**

- AUFK: order type, plant, description, deletion flag (LOEKZ)
- AFKO: GSTRP, GLTRP, GAMNG, AUFPL, RSNUM
- AFPO: MATNR, PSMNG, WEMNG, MEINS
- RESB: MATNR, BDMNG, ENMNG, RSPOS, XLOEK

#### Joins, keys and S/4HANA notes

**Body:** AUFK, AFKO and AFPO join on MANDT and AUFNR. RESB joins to AFKO through RSNUM (and AUFNR to be safe), and operations join through AUFPL. In S/4HANA these tables remain, but material documents moved to MATDOC and some master data became business-partner based, so joins from orders to goods movements should use MATDOC instead of MKPF and MSEG for new code. Statuses are stored in JEST through the OBJNR from AUFK.

#### Common mistakes

**Body:** Joining RESB on AUFNR alone and getting reservation rows from other documents. Forgetting the deletion flags on orders and components. Using AFPO.PSMNG as the order quantity when the order has multiple items. Reporting without checking status in JEST, so technically complete or closed orders are mixed with open ones. Querying a production database directly, which is better done through CDS views or ABAP with authority checks.

**Cta:** If you would rather ask 'which orders are late and short of components?' than write joins, we can put a private AI layer over SAP that stays inside your network.

**Faq:**

#### What is the manufacturing order table in SAP?

**Answer:** There are several. AUFK is the order master, AFKO the production order header with scheduling, AFPO the items, RESB the component requirements and AFVC the operations. Together they describe one production order.

#### How are AUFK and AFKO linked?

**Answer:** They join on client and order number (MANDT and AUFNR). AUFK holds general order data for all order categories, and AFKO adds production order specific header data such as dates, quantities and the routing and reservation numbers.

#### How do I get production order components?

**Answer:** Read RESB through the reservation number RSNUM from AFKO. Filter out deleted rows with XLOEK, and use BDMNG for the requirement and ENMNG for the quantity withdrawn. Joining on RSNUM and AUFNR keeps only that order's components.

#### Do these tables change in S/4HANA?

**Answer:** The order tables stay the same, which is why most PP reports survive migration. The changes are around them: material documents are in MATDOC, and some master data and pricing structures differ. Check field lengths such as material number in your release.

## Search terms

manufacturing order table in sap, sap production order tables, aufk afko afpo, sap resb production order components, sap production order sql, sap process order table, sap afko aufk join, sap order header table

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
