# Automatic Delivery Completed Flag for Old Open Purchase Order Items Program

> A custom background program that selects purchase order items by rule, those whose remaining quantity is below a tolerance or whose delivery date passed long ago with no goods receipt expected, and sets them to delivery completed. This cleans up open order lists and removes unnecessary order commitments on cost centers or projects.

- Type: Program, Custom development, Background program
- Module: MM
- Estimated effort: M (3–5 working days)
- Last updated: 2026-11-17
- URL: https://nekuhub.com/en/programs/automatic-delivery-completed-flag-for-old-open-purchase-order-items-program/


## Why is the standard not enough?

The delivery completed flag is set by hand in ME22N item by item. Mass maintenance (MASS / MEMASSPO) needs the records to be selected by hand and does not apply business rules such as the remaining quantity percentage, days since the last goods receipt or invoices waiting. Items partially received years ago therefore keep showing as open in ME2N and remain as commitments in CJI5 or KSB1.

### Closest standard alternatives

- ME22N: Sets the delivery completed flag by hand on one order item.
- ME2N: Lists open items; cannot apply rules or set the flag.

## Tables used

| Table | Role | Access | Join | System |
|---|---|---|---|---|
| EKKO | Order header: company code, purchasing organization, document type, vendor (driving table) | Read | - | ECC + S/4 |
| EKPO | Order item: quantity and the delivery completed flag (ELIKZ) is updated | Write | EKPO-EBELN = EKKO-EBELN | ECC + S/4 |
| EKET | Schedule line: latest delivery date | Read | EKET-EBELN = EKPO-EBELN AND EKET-EBELP = EKPO-EBELP | ECC + S/4 |
| EKBE | Order history: received and invoiced quantity, last receipt date | Read | EKBE-EBELN = EKPO-EBELN AND EKBE-EBELP = EKPO-EBELP | ECC + S/4 |

## BAPIs and functions used

- BAPI_PO_CHANGE: Sets the delivery completed indicator on the order item
- BAPI_TRANSACTION_COMMIT: Saves the changes permanently per order
- BAPI_TRANSACTION_ROLLBACK: Rolls back changes in test mode or on error

## Selection screen parameters

| Parameter | Description | Type | Reference field | Required |
|---|---|---|---|---|
| S_BUKRS | Company code | Range / multiple | EKKO-BUKRS | Yes |
| S_EKORG | Purchasing organization | Range / multiple | EKKO-EKORG | No |
| S_BSART | Order document type | Range / multiple | EKKO-BSART | No |
| S_WERKS | Plant | Range / multiple | EKPO-WERKS | No |
| P_RULE1 | Rule 1: remaining quantity below tolerance | Checkbox | - | No |
| P_TOLPCT | Remaining quantity tolerance (%) | Single value | - | No |
| P_RULE2 | Rule 2: delivery date and last receipt are old | Checkbox | - | No |
| P_DAYS | Days after the delivery date | Single value | - | No |
| P_TEST | Test mode (list without changing) | Checkbox | - | No |

## Result list columns

| Column | Source |
|---|---|
| Purchase order | EKPO-EBELN |
| Item | EKPO-EBELP |
| Vendor | EKKO-LIFNR |
| Material | EKPO-MATNR |
| Plant | EKPO-WERKS |
| Order qty | EKPO-MENGE |
| Received qty | Calculated: Σ EKBE-MENGE (VGABE = 1, reversals negative) |
| Remaining qty | Calculated: EKPO-MENGE − received qty |
| Remaining value | Calculated: Remaining qty × EKPO-NETPR ÷ EKPO-PEINH |
| Latest delivery date | EKET-EINDT |
| Last goods receipt | Calculated: Latest EKBE-BUDAT (VGABE = 1) |
| Rule | Calculated: The rule that made the item a candidate and its value |
| Status | Calculated: Completed, skipped or error |
| Message | Calculated: Skip reason or BAPI return message |

## How does the program work?

1. EKKO and EKPO are read by company code, purchasing organization, document type and plant; items whose delivery completed (ELIKZ) and deletion (LOEKZ) flags are blank and that expect a goods receipt remain.
2. Net goods receipts (VGABE = 1) and invoiced quantity (VGABE = 2) are summed from EKBE and the last receipt date is found; the latest delivery date (EINDT) comes from EKET.
3. Rule 1: remaining quantity ÷ order quantity × 100 ≤ tolerance percentage. Rule 2: the latest delivery date and the last goods receipt are older than P_DAYS days. If either rule is met, the item becomes a candidate.
4. Exceptions: if the invoiced quantity is above the received quantity (invoice waiting), or an open inbound delivery or shipping notification exists, the item is skipped and the reason is written to the list.
5. Candidates are changed per order with BAPI_PO_CHANGE using POITEM-NO_MORE_GR = X and the POITEMX flag; in test mode the BAPI runs with its test flag and BAPI_TRANSACTION_ROLLBACK follows. In a real run BAPI_TRANSACTION_COMMIT is done per order, and the result list can be emailed to the purchasing groups.

## Authorization objects

- M_BEST_BSA: Purchase order change authorization by document type
- M_BEST_EKO: Purchase order change authorization by purchasing organization
- M_BEST_WRK: Purchase order change authorization by plant

## Frequently asked questions

### Can goods still be received on an item that was flagged?

Yes. The delivery completed flag does not block goods receipts; it only removes the item from open lists and commitments. If needed, the flag can be removed in ME22N.

### How are project and cost center commitments affected?

The order commitment for the remaining quantity is reduced when the flag is set. The program is therefore also used to clean up inflated commitments in project and budget reports.

### Does the program work on S/4HANA?

Yes. BAPI_PO_CHANGE and the order tables are the same in S/4HANA. Standard order closing apps in S/4HANA can also be used; this program adds company-specific rules and exceptions.

---
Let us build this program for your system: https://nekuhub.com/en/request-a-quote/?report=mm-po-auto-delivery-completed
