SAP Reference
CO02
ChangeS/4 · ActiveChange Production Order
Boilerplate SQL
Databricks SQLStarting point for querying the tables behind this transaction. Adjust the WHERE clause for your scenario.
-- ============================================================
-- T-Code : CO02 Change Production Order
-- Purpose: Change an existing production order (quantity, dates, operations)
-- Grain : One row per production order with first-line item and operation
-- Tables : AFKO, AFPO, AUFK, AFVC, MAKT, MARA, T001W
-- Notes : AFVC joins to AFKO via AUFPL (routing number), NOT AUFNR — otherwise you get a Cartesian product on operations. Status evaluation requires JEST + TJ02T lookup (see JEST trick at end).
-- ============================================================
SELECT
-- Keys
h.MANDT AS "Client",
h.AUFNR AS "Order Number",
l.POSNR AS "Order Item",
-- Descriptive text
ord.KTEXT AS "Short Text",
mt.MAKTX AS "Material Description",
-- Quantities + UOM (paired)
h.GAMNG AS "Total Order Quantity",
h.GMEIN AS "Order Unit of Measure",
l.PSMNG AS "Item Quantity",
l.WEMNG AS "Delivered Quantity",
(l.PSMNG - l.WEMNG) AS "Open Quantity",
l.PSAMG AS "Scrap Quantity",
-- Dates
h.GSTRP AS "Basic Start Date",
h.GLTRP AS "Basic Finish Date",
h.GSTRS AS "Scheduled Start",
h.GLTRS AS "Scheduled Finish",
h.FTRMI AS "Actual Release Date",
ord.ERDAT AS "Created On",
-- Status / indicators
ord.OBJNR AS "Object Number (JEST/TJ02T)",
h.STAT AS "System Status (Text)",
ord.USER0 AS "User Status",
-- Org fields
l.DWERK AS "Plant",
pt.NAME1 AS "Plant Name",
ord.BUKRS AS "Company Code",
h.FEVOR AS "Production Scheduler",
-- Master data enrichment
ord.AUART AS "Order Type",
h.PLNBEZ AS "Material Number",
m.MTART AS "Material Type",
m.MATKL AS "Material Group",
h.DISPO AS "MRP Controller",
h.PLNNR AS "Routing Group",
h.PLNAL AS "Group Counter"
FROM afko h
INNER JOIN afpo l
ON l.MANDT = h.MANDT
AND l.AUFNR = h.AUFNR
INNER JOIN aufk ord
ON ord.MANDT = h.MANDT
AND ord.AUFNR = h.AUFNR
LEFT JOIN makt mt
ON mt.MANDT = l.MANDT
AND mt.MATNR = l.MATNR
AND mt.SPRAS = 'E'
LEFT JOIN mara m
ON m.MANDT = l.MANDT
AND m.MATNR = l.MATNR
LEFT JOIN t001w pt
ON pt.MANDT = l.MANDT
AND pt.WERKS = l.DWERK
WHERE
h.MANDT = '100'
AND ord.ERDAT BETWEEN '<DATE_FROM>' AND '<DATE_TO>'
-- AND l.DWERK = '<WERKS>'
-- AND h.AUFNR = '<AUFNR>'
ORDER BY h.GLTRP, h.AUFNR;Tables Used by This Transaction
How these tables connect. Nodes are clickable.