SAP Outline Agreement Expiry Report ABAP SELECT Generator
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.
Fill in
ABAP report
REPORT ZMM_CONTRACT_EXPIRY.
TABLES: ekko.
PARAMETERS: p_days TYPE i DEFAULT 90,
p_bstyp TYPE ekko-bstyp DEFAULT 'K'.
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
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).
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.
Ask SAP which contracts expire next
An optional walkthrough of a read-only assistant over SAP purchasing data.
Optional. The tool and every export work without this. No spam.
How to use the generator
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.
- 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
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
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
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.
Frequently Asked Questions
Which SAP transaction shows contract validity?
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?
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?
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?
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.
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.
Related Tools
Contract Expiry and Notice Deadline SQL Query Generator
Generate a SQL query that finds contracts expiring soon and the last day to send a non-renewal notice, using your table and column names.
Compliance & ContractsContract Obligations Matrix Worksheet
An editable matrix of contract obligations with owner, due date, reminder lead and value at stake.
Compliance & ContractsManufacturing Contract Risk Exposure Assessment
Ten questions that score how well your contract practices control liability, IP, flowdown and renewal risk.
Compliance & ContractsEquipment Purchase Contract Review Checklist
A buyer's checklist of what to confirm before signing a contract for CNC machines, lines or other capital equipment.