SAPFree generatorPDF, Excel, Word exportSAP ECC and S/4HANADiscrete Manufacturing

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

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.

Fill in

Generated code
Download:

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

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 = '100'
  AND  k.werks = '1000'
  AND  k.auart = 'PP01'
  AND  h.gstrp BETWEEN '20260101' AND '20261231'
  AND  k.loekz = ''
ORDER BY k.aufnr;

Add components (RESB through reservation number)

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 = '100'
  AND  k.werks = '1000'
  AND  k.auart = 'PP01'
  AND  h.gstrp BETWEEN '20260101' AND '20261231'
  AND  r.xloek = ''
ORDER BY k.aufnr, r.rspos;

Add operations (AFVC through order routing number)

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 = '100'
  AND  h.aufnr = :aufnr
ORDER BY v.vornr;

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.

Production order questions without joins

Optional: a private read-only AI layer over SAP PP, on your servers.

Optional. The tool and every export work without this. No spam.

How to use the generator

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

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.

  • 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

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

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.

Frequently Asked Questions

What is the manufacturing order table in SAP?

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?

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?

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?

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.

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.