# SAP Outline Agreement Expiry Report ABAP SELECT Generator

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

## Short answer

Generate an ABAP report that lists purchasing contracts and scheduling agreements expiring in a window, from EKKO and EKPO.

## Category

sap

## Erp

SAP S/4HANA

## Audience

- SAP developer
- SAP MM consultant
- Buyer
- Contracts manager

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Report name

**Key:** report

**Type:** text

**Default:** ZMM_CONTRACT_EXPIRY

#### Default look-ahead days

**Key:** days

**Type:** number

**Default:** 90

#### Document category (K contract, L scheduling agreement)

**Key:** doc_cat

**Type:** select

**Options:**

- K
- L

**Default:** K

**Blocks:**

#### ABAP report

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

TABLES: ekko.

PARAMETERS: p_days TYPE i DEFAULT {{days}},
            p_bstyp TYPE ekko-bstyp DEFAULT '{{doc_cat}}'.
SELECT-OPTIONS: s_ekorg FOR ekko-ekorg,
                s_lifnr FOR ekko-lifnr.

TYPES: BEGIN OF ty_out,
         ebeln TYPE ekko-ebeln,
         bsart TYPE ekko-bsart,
         lifnr TYPE ekko-lifnr,
         ekorg TYPE ekko-ekorg,
         ekgrp TYPE ekko-ekgrp,
         kdatb TYPE ekko-kdatb,
         kdate TYPE ekko-kdate,
         items TYPE i,
         days_left TYPE i,
       END OF ty_out.

DATA: lt_out TYPE STANDARD TABLE OF ty_out,
      lv_limit TYPE d.

START-OF-SELECTION.
  lv_limit = sy-datum + p_days.

  SELECT k~ebeln, k~bsart, k~lifnr, k~ekorg, k~ekgrp, k~kdatb, k~kdate,
         COUNT( * ) AS items
    FROM ekko AS k
    INNER JOIN ekpo AS p ON p~ebeln = k~ebeln
    WHERE k~bstyp = @p_bstyp
      AND k~kdate BETWEEN @sy-datum AND @lv_limit
      AND k~ekorg IN @s_ekorg
      AND k~lifnr IN @s_lifnr
      AND p~loekz = @space
    GROUP BY k~ebeln, k~bsart, k~lifnr, k~ekorg, k~ekgrp, k~kdatb, k~kdate
    ORDER BY k~kdate
    INTO CORRESPONDING FIELDS OF TABLE @lt_out.

  LOOP AT lt_out ASSIGNING FIELD-SYMBOL(<fs>).
    <fs>-days_left = <fs>-kdate - sy-datum.
  ENDLOOP.

  cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_alv)
                          CHANGING  t_table      = lt_out ).
  lo_alv->get_functions( )->set_all( abap_true ).
  lo_alv->display( ).

#### Notes on the fields used

**Body:** EKKO-BSTYP: K = contract, L = scheduling agreement.
EKKO-KDATB: start of validity period.
EKKO-KDATE: end of validity period.
EKKO-EKORG: purchasing organization. EKKO-EKGRP: purchasing group.
EKPO-LOEKZ: deletion indicator on the item.
To open a contract from the list, use transaction ME33K (display contract) or ME33L (display scheduling agreement).

**Notes:** Uses open SQL with the @ host variable syntax, so it needs a release that supports it (ABAP 7.40 SP05 or later). On older systems, rewrite with classic INTO TABLE syntax. Add authority checks for M_BEST_EKO before production use, and test in a sandbox. Verify field names in SE11 for your release.

## Content

**Intro:** SAP shows contract validity per document in ME33K, but there is no standard list that shows everything ending in the next quarter. This generator produces a short ABAP report that does it from EKKO and EKPO.

**Sections:**

#### How to use the generator

**Body:** Set a report name in the customer namespace, the default look-ahead and the document category. Paste the code into SE38, activate it and run it with a selection on purchasing organization and vendor. The output is an ALV grid you can sort and export. Because it reads standard tables only, it is safe to run, but add an authorization check before you release it to buyers.

**Bullets:**

- Create it in the Z namespace in a dev system
- Add the authorization check for your organization
- Transport it through your normal landscape
- Schedule it as a background job if you want email output

#### The tables and fields

**Body:** Outline agreements live in EKKO at header level. Contracts have document category K and scheduling agreements have L. The validity period sits in KDATB and KDATE. Item data is in EKPO, where LOEKZ marks deleted lines. Joining to EKPO lets you count active items and avoid listing contracts whose lines were all deleted.

#### Extending the report

**Body:** Common additions are vendor name from LFA1, target value from EKKO-KTWRT, released quantity from EKPO-KTMNG, and the status of release strategy. If you use central contracts in S/4HANA, the data model differs and you should check the central contract objects for your release instead of assuming this query covers them.

#### Common mistakes

**Body:** Do not rely on validity end alone if buyers extend contracts through change documents without updating the date. Do not forget that blocked or deleted headers may still appear unless you filter them. And do not ship the code without testing performance on a production-sized EKKO, because a missing index on a custom selection can slow the report.

**Cta:** If you would rather ask which contracts expire next quarter in plain language and get the result from live data, Netray can build that over SAP as a read-only assistant.

**Faq:**

#### Which SAP transaction shows contract validity?

**Answer:** ME33K shows a purchasing contract and its validity dates, ME33L does the same for scheduling agreements. For lists, ME3N and ME80FN can filter outline agreements, depending on your release and authorizations.

#### Does this cover S/4HANA central contracts?

**Answer:** Not fully. Central contracts use a separate structure, so check the relevant tables for your release. This generator targets classic purchasing contracts and scheduling agreements in EKKO and EKPO.

#### What does the BSTYP value mean?

**Answer:** BSTYP is the purchasing document category. K is a contract and L is a scheduling agreement. Other values include F for purchase order and A for request for quotation.

#### Can I run this without a developer?

**Answer:** You need access to SE38 and a development system, so a developer or basis admin should activate and transport it. Business users then run it from a transaction code you create.

## Search terms

sap contract expiry report abap, ekko kdate validity end, sap outline agreement expiring, me3n contract validity report, sap scheduling agreement expiry select, ekko bstyp k contract, sap purchasing contract expiry alert, abap report contracts ending soon

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