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

> Source: https://netray.co/tools/sap-abap-stock-below-safety-stock-report-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Produces a small ABAP report that joins MARC and MARD to list materials with unrestricted stock under the safety stock for a plant and MRP controller.

## Category

sap

## Erp

SAP

## Audience

- ABAP developer
- SAP MM consultant
- Materials planner

## Tool

**Kind:** template

**Output:** code

**Language:** abap

**Fields:**

#### Report name

**Key:** report

**Type:** text

**Default:** ZMM_BELOW_SAFETY_STOCK

#### Plant

**Key:** plant

**Type:** text

**Default:** 1000

#### MRP controller

**Key:** mrp_ctrl

**Type:** text

**Default:** 001

#### Maximum rows

**Key:** max_rows

**Type:** number

**Default:** 500

**Blocks:**

#### Report source

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

PARAMETERS: p_werks TYPE marc-werks DEFAULT '{{plant}}' OBLIGATORY,
            p_dispo TYPE marc-dispo DEFAULT '{{mrp_ctrl}}'.

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 {{max_rows}} 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

**Body:** * 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.

**Notes:** 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.

## Content

**Intro:** 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.

**Sections:**

#### How to use the generator

**Body:** 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.

**Bullets:**

- 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

**Body:** 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

**Body:** 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

**Body:** 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.

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

**Faq:**

#### Which SAP tables does this use?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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.

## Search terms

abap below safety stock, sap marc mard join, sap safety stock report abap, eisbe labst select, sap stock below safety stock, abap open sql group by having, sap mrp controller report, abap report material stock

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