# SAP Open Purchase Order Items ABAP SELECT Generator

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

## Short answer

Fill in plant, document type and dates to generate ABAP Open SQL that lists open PO items with received quantity from EKBE.

## Category

sap

## Erp

SAP S/4HANA

## Audience

- ABAP developer
- SAP MM consultant

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Plant

**Key:** plant

**Type:** text

**Default:** 1000

#### PO document type

**Key:** doc_type

**Type:** text

**Default:** NB

#### PO date from (YYYYMMDD)

**Key:** date_from

**Type:** text

**Default:** 20260101

#### PO date to (YYYYMMDD)

**Key:** date_to

**Type:** text

**Default:** 20261231

#### Report name

**Key:** report

**Type:** text

**Default:** ZMM_OPEN_PO_ITEMS

**Blocks:**

#### Report with open PO items

**Body:** REPORT {{report}}.

TYPES: BEGIN OF ty_po,
         ebeln TYPE ekko-ebeln,
         ebelp TYPE ekpo-ebelp,
         lifnr TYPE ekko-lifnr,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         menge TYPE ekpo-menge,
         meins TYPE ekpo-meins,
       END OF ty_po.

DATA: lt_po TYPE STANDARD TABLE OF ty_po,
      lv_rec TYPE ekbe-menge.

SELECT k~ebeln p~ebelp k~lifnr p~matnr p~werks p~menge p~meins
  FROM ekko AS k
  INNER JOIN ekpo AS p ON p~ebeln = k~ebeln
  WHERE k~bsart = '{{doc_type}}'
    AND k~bedat BETWEEN '{{date_from}}' AND '{{date_to}}'
    AND k~loekz = ''
    AND p~werks = '{{plant}}'
    AND p~loekz = ''
    AND p~elikz = ''
  INTO CORRESPONDING FIELDS OF TABLE lt_po.

LOOP AT lt_po ASSIGNING FIELD-SYMBOL(<po>).
  CLEAR lv_rec.
  SELECT SUM( menge ) FROM ekbe
    INTO lv_rec
    WHERE ebeln = <po>-ebeln
      AND ebelp = <po>-ebelp
      AND vgabe = '1'
      AND shkzg = 'S'.
  WRITE: / <po>-ebeln, <po>-ebelp, <po>-matnr, <po>-menge, lv_rec.
ENDLOOP.

#### Open quantity logic

**Body:** * Open quantity = ordered quantity (EKPO-MENGE) minus received quantity.
* Received quantity = sum of EKBE-MENGE where VGABE = '1' (goods receipt).
* Subtract reversals (EKBE-SHKZG = 'H') if you want net receipts.
* ELIKZ = 'X' means delivery completed, so those items are excluded.

**Notes:** Starting point, not production code. Replace the loop SELECT with a join or FOR ALL ENTRIES on large volumes, add authority checks (M_BEST_WRK for plant) and review the field list against your release. Test in a sandbox before use.

## Content

**Intro:** A list of open purchase order items is one of the most requested custom reports in SAP MM. This generator produces a clean ABAP starting point that joins the header, item and history tables.

**Sections:**

#### How to use the generator

**Body:** Enter your plant, PO document type, a date range and a report name. The tool fills the placeholders in an ABAP report that selects open items from EKKO and EKPO, then reads goods receipt quantities from EKBE. Copy the code into SE38 or an ABAP development tool, activate it and run it. Adjust the field list and output to your needs, for example an ALV grid instead of WRITE.

#### How open quantity is determined

**Body:** An item is considered open when its delivery completed flag ELIKZ is empty, deletion indicator LOEKZ is empty and the received quantity is below the ordered quantity. Received quantity comes from the PO history in EKBE, where history category VGABE equals 1 is a goods receipt and the debit or credit indicator SHKZG separates receipts from reversals. For scheduling agreements use EKET for schedule line quantities instead of EKPO.

**Bullets:**

- EKPO-ELIKZ = X means delivery completed
- EKBE-VGABE = 1 means goods receipt
- EKBE-SHKZG = H marks a reversal or return
- EKET-MENGE holds scheduled quantities by line

#### Performance and common mistakes

**Body:** Selecting inside a loop is easy to read but slow on large volumes, so batch the history read with FOR ALL ENTRIES or a join and aggregate in memory. Always filter by plant and date because EKPO and EKBE are large tables. Remember that valuation and quantity can differ when the order unit differs from the base unit, which affects goods receipts. In S/4HANA you can use released CDS views and the open purchase order Fiori apps rather than custom code.

**Cta:** If your buyers need open PO views by supplier, plant and due date without waiting for ABAP changes, ask us about a read-only natural language layer with the query shown.

**Faq:**

#### Which tables do I need for open purchase orders?

**Answer:** EKKO for the header, EKPO for the item and EKBE for the goods receipt history. For scheduling agreements and delivery dates add EKET. Join EKKO to EKPO on EBELN and read EKBE using EBELN and EBELP.

#### How do I exclude completed items?

**Answer:** Filter out items with delivery completed set (ELIKZ = X) and deletion indicator set (LOEKZ not empty). Also compare ordered and received quantities, since a partial receipt leaves the item open even if no completion flag is set.

#### Is this code safe to run in production?

**Answer:** It is read-only, but you should review it, add authorization checks and test volumes in a quality system first. Large unfiltered selects on EKPO and EKBE can slow the system, so always include plant, date and document type filters.

#### Does it work in S/4HANA?

**Answer:** Yes, EKKO, EKPO and EKBE remain in S/4HANA. For new development consider released CDS views and standard Fiori apps. This code is a simple starting point and uses basic Open SQL that runs on both ECC and S/4HANA.

## Search terms

abap select open purchase orders, sap open po items query, ekko ekpo join abap, sap ekbe goods receipt quantity abap, abap open sql purchase order report, sap open po report code, sap po open quantity calculation, se38 open po report

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