Retrieve Stock Quantity
This sample shows how to check the availability of materials using the BAPI BAPI_MATERIAL_AVAILABILITY.
About
BAPI_MATERIAL_AVAILABILITY shows the availability of a material. This availability provides the so-called ATP (stock quantity Available To Promise). BAPI_MATERIAL_AVAILABILITY requires at least three import parameters:
- the Plant (PLANT)
- the material number (MATERIAL)
- the unit (UNIT)
The Windows form for the BAPI BAPI_MATERIAL_AVAILABILITY contains the following elements:
- Three text boxes for import parameters: txtPlant, txtMaterial and txtUnit
- One Button: btnGetQuantity
- Two text boxes to display results: txtStock and txtBAPIMessage
Call BAPI_MATERIAL_AVAILABILITY
Follow the steps below to call the BAPI API_MATERIAL_AVAILABILITY:
- Connect to the SAP system using
R3Connection
. - Create an RFCFunction object using
CreateFunction
. - Assign the import parameters to the RFCFunction object.
- Execute the function module using
Execute
. - If the BAPI returns an error, display the error message in the Windows form.
If no error occurred, the BAPI returns the parameter AV_QTY_PLT that contains the stock quantity in the given unit. Display the stock quantity in the Windows form.
Output:
- User enters a non-existing material number:
- User enters a valid material number:
Last update: January 30, 2024