# API_MATERIAL_STOCK_SRV: reading SAP stock by plant and storage location with OData

> Source: https://netray.co/erp-help/api-material-stock-srv-odata-sap-stock-by-plant-storage-location
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: ERP Help

## Short answer

API_MATERIAL_STOCK_SRV is the released OData V2 service for reading material stock in S/4HANA. Its main entity set, A_MatlStkInAcctMod, returns stock quantities by material, plant, storage location, batch and stock type. Activate the service, authorize a technical user and filter with $filter on Material and Plant.

## Kind

how-to

## System

sap

## Erp

SAP S/4HANA

## Module

Inventory Management / OData APIs

## Query

api_material_stock

## Alternate Queries

- API_MATERIAL_STOCK_SRV
- sap odata material stock api
- A_MatlStkInAcctMod example

## Applies To

SAP S/4HANA on-premise and private cloud (service path /sap/opu/odata/sap/API_MATERIAL_STOCK_SRV). Check the SAP Business Accelerator Hub for the exact entities in your release.

## Steps

### Call the material stock service

**Items:**

- Check the service in the SAP Business Accelerator Hub (api.sap.com) to confirm the entity sets available for your release.
- Activate the service in /IWFND/MAINT_SERVICE on the gateway (or the embedded gateway): Add Service, select API_MATERIAL_STOCK_SRV, and assign the system alias and package.
- Create a technical user and a role that includes the service in the authorization defaults (S_SERVICE) and read access to the stock data for the plants it may see.
- Test in /IWFND/GW_CLIENT with a request such as the example below, using HTTP GET and the header Accept: application/json.
- From your integration, authenticate (basic over TLS or OAuth/SAML as set up by your basis team) and call the same URL with $filter, $select and $top.
- For writes you do not use this service: stock changes happen through goods movements (material document APIs), never by posting to the stock entities.

## Sections

### Entities and sample requests

**Body:**

The commonly used entity set is A_MatlStkInAcctMod, which exposes one row per material, plant, storage location, batch, special stock indicator and stock type, with the quantity in the base unit. Typical key properties are Material, Plant, StorageLocation, Batch, Supplier, Customer, WBSElementInternalID, SDDocument, SDDocumentItem, InventorySpecialStockType and InventoryStockType, and the quantity field is MatlWrhsStkQtyInMatBaseUnit with MaterialBaseUnit. A separate entity set exposes the material level view. Confirm the names in the metadata document before coding.

Always filter. An unfiltered call on a production system returns a large result and will time out or hit the server's limits. Combine $filter on Material and Plant with $select for the columns you need and use $top and $skip for paging.

**Code:**

- GET /sap/opu/odata/sap/API_MATERIAL_STOCK_SRV/$metadata
- 
- GET /sap/opu/odata/sap/API_MATERIAL_STOCK_SRV/A_MatlStkInAcctMod
-   ?$filter=Material eq 'FG-1000' and Plant eq '1010'
-   &$select=Material,Plant,StorageLocation,Batch,InventoryStockType,MatlWrhsStkQtyInMatBaseUnit,MaterialBaseUnit
-   &$format=json

### Stock types and how to interpret quantities

**Body:**

Quantities are split by stock type. Unrestricted use, quality inspection and blocked stock are separate rows, identified by InventoryStockType. If your integration shows less than the MMBE total, you are probably filtering on one type, or you are not including special stock such as consignment or project stock.

Remember that the service reads the current stock, not the stock at a past date. For historical balances use the material document tables or an analytical service intended for stock over time. Also keep in mind that unconfirmed goods movements and reservations are not stock, so availability (ATP) is a different calculation.

### Authorization, performance and common errors

**Body:**

A 403 or 401 usually means the user lacks the service authorization or the role has no start authorization for the service, while empty results with a 200 often mean the plant authorization (M_MSEG_WWE or related) hides the data. A 404 means the service is not activated on the gateway you are calling, or the system alias is wrong. Check the gateway error log in /IWFND/ERROR_LOG for the real cause.

For performance, avoid polling thousands of materials. Call once per plant with a filter or use a delta mechanism: subscribe to material document events in your integration layer and refresh only materials that moved. Keep API traffic off the main application server when you can by using a dedicated gateway or a rate limit.

## Pitfalls

- Calling without a filter and getting timeouts or truncated pages.
- Reading the total from one stock type and calling it 'available'.
- Using a dialog user for integration: use a technical user with a minimal role.
- Hard coding entity names without reading $metadata, which differ between releases.
- Trying to change stock by posting to the entity set: use goods movement APIs.

## Ai Angle

If you want people to ask 'how much of part X is in plant 1010' without writing OData, a read-only assistant over this API or the underlying tables can translate the question into a filtered call and show the call it made. With ERPray the service user is limited to the roles you grant, and on-prem deployment keeps the stock figures and the model inside your network.

## Faq

### What is API_MATERIAL_STOCK_SRV?

**Answer:** It is a released SAP OData V2 service that exposes material stock data in S/4HANA. You use it to read stock by material, plant, storage location, batch and stock type from external systems, dashboards or integrations.

### How do I filter stock for one plant and storage location?

**Answer:** Append $filter=Plant eq '1010' and StorageLocation eq '0001' to the A_MatlStkInAcctMod request, add Material when you can, and use $select to limit columns. Use $top and $skip to page large results.

### Why does the service return 404?

**Answer:** The service is probably not activated in /IWFND/MAINT_SERVICE on the system you call, or the URL or system alias is wrong. Check the gateway error log and the service catalog on that host.

### Can I update stock through this API?

**Answer:** No. It is for reading. Stock changes come from goods movements posted with material document APIs or BAPIs, which create documents and update quantities and values consistently.

## Search terms

api_material_stock, API_MATERIAL_STOCK_SRV, A_MatlStkInAcctMod, sap odata stock by plant, sap material stock api, sap inventory odata service, iwfnd maint_service activate, sap stock api storage location

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