# SAP Process Order ABAP SELECT Snippet Generator

> Source: https://netray.co/tools/sap-process-order-select-abap-snippet-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in plant, order type and date, and get an ABAP SELECT that returns SAP process orders with header dates, quantities and materials.

## Category

sap

## Erp

SAP ECC / S/4HANA

## Industry

Chemical Manufacturing

## Audience

- ABAP developer
- SAP PP-PI consultant
- SAP basis analyst

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Plant (WERKS)

**Key:** plant

**Type:** text

**Default:** 1000

#### Process order type (AUART)

**Key:** order_type

**Type:** text

**Default:** YBM1

**Help:** Use the order type configured in your system.

#### Scheduled start from (YYYYMMDD)

**Key:** start_date

**Type:** text

**Default:** 20261001

#### Material number (MATNR) or blank

**Key:** material

**Type:** text

#### Maximum rows

**Key:** max_rows

**Type:** number

**Default:** 500

**Blocks:**

#### Process order list

**Body:** * Process orders (order category 40) joined across header and item
TYPES: BEGIN OF ty_po,
         aufnr TYPE aufk-aufnr,
         auart TYPE aufk-auart,
         werks TYPE aufk-werks,
         gstrp TYPE afko-gstrp,
         gltrp TYPE afko-gltrp,
         gamng TYPE afko-gamng,
         gmein TYPE afko-gmein,
         matnr TYPE afpo-matnr,
         psmng TYPE afpo-psmng,
         wemng TYPE afpo-wemng,
       END OF ty_po.

DATA lt_po TYPE STANDARD TABLE OF ty_po WITH EMPTY KEY.
DATA lv_matnr TYPE afpo-matnr VALUE '{{material}}'.

SELECT k~aufnr, k~auart, k~werks,
       o~gstrp, o~gltrp, o~gamng, o~gmein,
       p~matnr, p~psmng, p~wemng
  FROM aufk AS k
  INNER JOIN afko AS o ON o~aufnr = k~aufnr
  INNER JOIN afpo AS p ON p~aufnr = k~aufnr
  WHERE k~autyp = '40'
    AND k~werks = '{{plant}}'
    AND k~auart = '{{order_type}}'
    AND o~gstrp >= '{{start_date}}'
    AND k~loekz = ''
  ORDER BY o~gstrp, k~aufnr
  INTO CORRESPONDING FIELDS OF TABLE @lt_po
  UP TO {{max_rows}} ROWS.

IF lv_matnr IS NOT INITIAL.
  DELETE lt_po WHERE matnr <> lv_matnr.
ENDIF.

IF sy-subrc <> 0 OR lt_po IS INITIAL.
  WRITE: / 'No process orders found'.
ENDIF.

#### Output loop for a quick test

**Body:** LOOP AT lt_po ASSIGNING FIELD-SYMBOL(<po>).
  WRITE: / <po>-aufnr, <po>-matnr, <po>-gstrp, <po>-psmng, <po>-gmein.
ENDLOOP.

**Notes:** Verify field names and the order category on your release: AUTYP 40 identifies process orders in standard systems. In S/4HANA, check for custom views and authorization needs, add an authority check for plant (C_AFKO_ATY or your standard), and never run unrestricted selects in production dialog sessions.

## Content

**Intro:** Process orders in SAP PP-PI are stored across the order master AUFK, the PP header AFKO and the order item AFPO. This generator builds an ABAP SELECT that joins the three tables for a plant and order type, giving a starting point for a quick report or a data extract.

**Sections:**

#### How to use the generator

**Body:** Enter the plant, process order type and the earliest scheduled start date in the form YYYYMMDD, then copy the generated code into a test report or a local class. The query filters on order category 40, which identifies process orders, and excludes orders flagged for deletion. The optional material filter is applied after the select, which is simple but not optimal for large volumes, so add it to the WHERE clause if you only ever need one material.

**Bullets:**

- Test in a development or quality client first
- Add a plant authority check before using it in a real report
- Use the row limit while exploring the data

#### What each table holds

**Body:** AUFK is the order master shared by all order types and holds the order number, order type, plant and status-related object number. AFKO holds the production order header data, including basic dates such as GSTRP and GLTRP and the total order quantity GAMNG. AFPO holds item-level data, including the material, planned quantity PSMNG and the delivered quantity WEMNG. Status details sit in the object status tables and are normally read with standard function modules rather than direct selects.

#### Common mistakes

**Body:** Frequent issues are forgetting the order category and accidentally mixing in production orders, using a date field type that does not match the stored format, and joining without considering multiple items per order. For released status, confirmations or batch details, use the standard function modules or CDS views where available, since table logic can be incomplete. In S/4HANA, check whether released views or APIs already provide what you need.

**Bullets:**

- Do not rely on direct reads for status logic
- Remember the date format is YYYYMMDD in character fields
- Check for multiple items on the same order

**Cta:** If you need process order reporting or an AI assistant over SAP PP-PI data without writing ABAP for each question, Netray can discuss a read-only approach that respects SAP roles.

**Faq:**

#### Which tables store SAP process orders?

**Answer:** The common ones are AUFK for the order master, AFKO for the PP header with dates and quantities, and AFPO for the order item with material. Components are in RESB and operations in AFVC and AFVV, reached through the routing link in AFKO.

#### How do I tell process orders from production orders?

**Answer:** Use the order category in AUFK-AUTYP. In standard SAP, 10 is a production order and 40 is a process order. Order types in AUART are customizing, so they differ between companies.

#### Can I use this in S/4HANA?

**Answer:** The tables still exist in S/4HANA and the syntax works with the modern ABAP release. Check released CDS views and APIs for new developments and respect authorization checks and performance guidelines.

#### Why is the status of the order not in the select?

**Answer:** System and user status are held in separate status tables linked by the object number, and are better read with standard function modules. Mixing them into a custom join is possible but easy to get wrong.

## Search terms

sap process order table, aufk afko afpo select, abap select process orders, sap pp-pi process order report abap, sap order category 40, process order afko gstrp, abap join aufk afko

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