SAPFree generatorPDF, Excel, Word exportSAP

SAP ABAP Report Generator: Materials Below Safety Stock (MARC and MARD)

A quick list of materials under their safety stock is one of the most requested custom reports in SAP MM. This generator writes a plain Open SQL report joining MARC and MARD that you can adapt, test and transport.

Fill in

Generated code
Download:

Report source

REPORT ZMM_BELOW_SAFETY_STOCK.

PARAMETERS: p_werks TYPE marc-werks DEFAULT '1000' OBLIGATORY,
            p_dispo TYPE marc-dispo DEFAULT '001'.

TYPES: BEGIN OF ty_low,
         matnr TYPE marc-matnr,
         werks TYPE marc-werks,
         eisbe TYPE marc-eisbe,
         minbe TYPE marc-minbe,
         labst TYPE mard-labst,
       END OF ty_low.
DATA lt_low TYPE STANDARD TABLE OF ty_low WITH EMPTY KEY.

SELECT m~matnr, m~werks, m~eisbe, m~minbe,
       SUM( d~labst ) AS labst
  FROM marc AS m
  INNER JOIN mard AS d
    ON d~matnr = m~matnr
   AND d~werks = m~werks
  WHERE m~werks = @p_werks
    AND m~dispo = @p_dispo
    AND m~eisbe > 0
  GROUP BY m~matnr, m~werks, m~eisbe, m~minbe
  HAVING SUM( d~labst ) < m~eisbe
  ORDER BY m~matnr
  INTO CORRESPONDING FIELDS OF TABLE @lt_low
  UP TO 500 ROWS.

IF lt_low IS INITIAL.
  WRITE: / 'No materials below safety stock.'.
ELSE.
  LOOP AT lt_low INTO DATA(ls_low).
    WRITE: / ls_low-matnr, ls_low-werks, ls_low-eisbe, ls_low-minbe, ls_low-labst.
  ENDLOOP.
ENDIF.

Variant: include shortfall and open purchase requisition quantity

* Shortfall = safety stock - unrestricted stock
LOOP AT lt_low ASSIGNING FIELD-SYMBOL(<l>).
  DATA(lv_short) = <l>-eisbe - <l>-labst.
  WRITE: / <l>-matnr, 'short by', lv_short.
ENDLOOP.

* Open requisitions: check table EBAN (fields MATNR, WERKS, MENGE, BSMNG, LOEKZ)
* before recommending new orders, to avoid duplicates.

Requires ABAP 7.40 SP08 or later for the inline declarations and @ host variable syntax; on older releases use classic declarations. Unrestricted stock (LABST) in MARD excludes quality inspection and blocked stock. Test in a sandbox, run through your transport process and add an authority check for plant (M_MATE_WRK) before production use.

Planner-ready stock exception report

Optional: convert this select into a governed report with approvals.

Optional. The tool and every export work without this. No spam.

How to use the generator

Enter a report name in your customer namespace, the plant and the MRP controller, and a row limit. Copy the code into SE38, activate it and run it with the selection screen. Replace the WRITE statements with an ALV grid when the output goes to end users, and add an authority check before it goes anywhere near production.

  • Use a Z or Y report name
  • Run first in a development or quality system
  • Keep the row limit while testing

How the select works

MARC holds plant level planning data including safety stock EISBE and reorder point MINBE. MARD holds stock by storage location, with unrestricted use stock in LABST. The join groups by material and plant, sums LABST over all storage locations, and keeps only rows where the sum is below EISBE. The HAVING clause compares an aggregate with a grouped column, which Open SQL allows when that column is in the group by list.

What it does not include

The report ignores stock in quality inspection (INSME), blocked stock (SPEME) and stock in transit. It also ignores open purchase orders, production orders and requisitions, so a material flagged here may already have supply coming. Use MD04 on any material you plan to act on, and cross check EBAN and EKPO for open documents.

Common mistakes

Forgetting that MARD has one row per storage location leads to counting each one separately. Selecting without a plant filter on a large system causes slow runs. Another mistake is treating time based safety stock, which uses range of coverage profiles, as if it were a fixed quantity in EISBE.

Frequently Asked Questions

Which SAP tables does this use?

MARC for plant level planning data such as EISBE, MINBE and DISPO, and MARD for storage location stock with LABST for unrestricted use. Both are standard tables in ECC and S/4HANA.

Will this work on S/4HANA?

MARC and MARD remain available as compatibility tables, but S/4HANA holds stock in MATDOC with MARD as a view in many releases. The select usually still works, so test it, and check your release notes.

Does it include stock in quality inspection?

No. Only unrestricted use stock LABST is summed. Add INSME for stock in quality inspection if your policy counts it toward safety stock.

Can I schedule it?

Yes. Create a variant and schedule the program in SM36, or send the result by email. Add an ALV output or a spool for the planners first.

Netray can turn reports like this into a read-only ERPray question that planners ask in plain language, with the select shown for review.