SAP Open Production Orders ABAP SELECT Statement Generator
A list of open production orders is the first report most plants ask for and the most frequently rewritten. This generator produces the Open SQL for it, using the real SAP tables, with a variant for late orders.
Fill in
Four character plant code (WERKS).
AUART of the production order type.
Open production orders in a plant
DATA: lv_werks TYPE werks_d VALUE '1000',
lv_auart TYPE aufart VALUE 'PP01',
lv_from TYPE d VALUE '20260901',
lv_to TYPE d VALUE '20261231'.
SELECT aufk~aufnr,
aufk~auart,
afpo~matnr,
afpo~psmng,
afpo~wemng,
afpo~meins,
afko~gstrp,
afko~gltrp
FROM aufk
INNER JOIN afko ON afko~aufnr = aufk~aufnr
INNER JOIN afpo ON afpo~aufnr = aufk~aufnr
WHERE aufk~werks = @lv_werks
AND aufk~auart = @lv_auart
AND afko~gstrp BETWEEN @lv_from AND @lv_to
AND NOT EXISTS ( SELECT objnr FROM jest
WHERE objnr = aufk~objnr
AND inact = ''
AND stat IN ('I0045','I0046','I0076') )
ORDER BY afko~gstrp, aufk~aufnr
INTO TABLE @DATA(lt_orders)
UP TO 500 ROWS.
cl_demo_output=>display( lt_orders ).Late orders: past due and not delivered
SELECT aufk~aufnr,
afpo~matnr,
afpo~psmng,
afpo~wemng,
afko~gltrp
FROM aufk
INNER JOIN afko ON afko~aufnr = aufk~aufnr
INNER JOIN afpo ON afpo~aufnr = aufk~aufnr
WHERE aufk~werks = @lv_werks
AND afko~gltrp < @sy-datum
AND afpo~wemng < afpo~psmng
AND NOT EXISTS ( SELECT objnr FROM jest
WHERE objnr = aufk~objnr
AND inact = ''
AND stat IN ('I0045','I0046','I0076') )
ORDER BY afko~gltrp
INTO TABLE @DATA(lt_late)
UP TO 500 ROWS.Status texts used above
* I0045 = TECO (technically completed) * I0046 = CLSD (closed) * I0076 = DLFL (deletion flag) * Add I0012 (DLV, delivered) if you also want to hide fully delivered orders.
Written for ABAP 7.4 and later Open SQL with host variables (@). On older releases remove the @ escapes and use the older INTO syntax. Verify field names in SE11, test in a sandbox and add authority checks (AUTHORITY-CHECK for object C_AUFK_ATY or your own) before using in a production report. A report reading all plants at once can be slow; keep the plant and date filters.
Production order reports without ABAP
Optional: see a demo of natural language reporting over SAP production orders, read-only and role aware.
Optional. The tool and every export work without this. No spam.
How to use the generator
Enter the plant, order type and scheduled start window. The code on the right updates immediately. Copy it into a report in SE38 or an ADT project. The first block lists orders still open, the second lists orders whose scheduled finish is past and whose delivered quantity is below the planned quantity. Replace cl_demo_output with an ALV if the list goes to users.
Why the status filter uses JEST
Order status is not a field on AFKO or AFPO. It lives in JEST, keyed by the object number AUFK-OBJNR, with one row per status and an INACT flag for statuses that were once set and later reversed. Filtering for TECO, CLSD and deletion flag (I0045, I0046, I0076) with INACT blank gives the orders that are still genuinely open. A NOT EXISTS subquery avoids duplicate rows that a plain join would cause.
- Date columns GSTRP and GLTRP are scheduled start and finish.
- PSMNG is planned quantity, WEMNG delivered quantity.
- Add JEST status I0002 (REL) in a positive EXISTS test to list only released orders.
Mistakes to avoid
Do not join AFKO to AFPO without understanding that multi-item orders (co-products) have more than one AFPO row; the join repeats header data. Do not forget the plant filter, because AUFK holds all order categories, including maintenance and internal orders, so also filter on order category if you only want production orders. Finally, check that the report is scoped before running in production, since tables like AFPO are large.
Frequently Asked Questions
Why does the query exclude status I0045?
I0045 is TECO, technically completed. Orders in TECO are no longer open for execution, even if they were not fully delivered. The query hides TECO, closed and deletion-flagged orders to leave the work that still needs attention.
Can I run this on ECC as well as S/4HANA?
The tables are the same, but the syntax with @ host variables and inline declarations needs ABAP 7.4 or later. For older systems, remove the @ symbols, declare the result table yourself and use the older INTO TABLE form.
How do I list only released orders?
Add a positive EXISTS subquery on JEST for status I0002 with INACT blank. Combine it with the not exists test on TECO and closed. The status I0002 means released (REL) in the standard status schema.
Does this query handle process orders?
Process orders from PP-PI use the same order tables with a different order category, so the join works, but you filter on the right order type and category. Components, phases and recipe data come from other structures, so extend the query accordingly.
Netray builds read-only query layers over SAP so planners can ask for late orders and shortages in plain language, without custom ABAP for each report. Tell us your landscape and we will scope it.
Related Tools
SAP BAPI Production Order Create and Release ABAP Template
Fill in material, plant, order type and dates and get an ABAP skeleton that creates and releases a production order with a commit.
SAPSAP PP Database Tables Reference
A lookup of the main SAP PP database tables, what each holds and the key fields to join on.
SAPSAP PP Transaction Codes Reference
A searchable cheat sheet of the SAP PP transaction codes planners and consultants use every day, grouped by area.
SAPSAP PP Planning Process Maturity Assessment
A ten question self-assessment of how well your SAP PP planning and execution processes work, with recommendations by score band.