How to use Warehouse Physical Stock by Product API in S/4HANA?
By default, the most of the standard APIs in Private Cloud / On-Premise installations are not active, as their service groups are not published (OData V4) or the services are not activated (OData V2).
For Warehouse physical stock service, when you try to open url
https://{host}:{port}/sap/opu/odata4/sap/api_whse_physstockprod/srvd_a2x/sap/whsephysicalstockproducts/0001
,
you receive an error:
... Service group 'API_WHSE_PHYSSTOCKPROD' is not published...
Follow the instructions below in order to publish the corresponding group.
Publishing an OData V4 Service Group
- Go to transaction
/IWFND/V4_ADMIN
SAP Gateway Service Administration. - Check that
API_WHSE_PHYSSTOCKPROD
service group is not listed in the section Service Groups, otherwise it is already published. If it is already published, you can skip this section. - Open publishing dialog using the button Publish Service Groups.
- Fill in the required parameters.
- System alias: usually “LOCAL”.
- Service group ID: "API_WHSE_PHYSSTOCKPROD".
- Find the corresponding service group using the button Get Service Groups (F8).
- Select it from the results list, publish it using the button Publish Service Groups.
Once published, the OData endpoint should become available.
Using it in your Fiori SAPUI5 application
- Update your
webapp/manifest.json
file.- Under "sap.app" → "dataSources", define a data source that points to the published OData V4 service. For example:
... "dataSources": { "warehousePhysicalStockService": { "uri": "/sap/opu/odata4/sap/api_whse_physstockprod/srvd_a2x/sap/whsephysicalstockproducts/0001/", "type": "OData", "settings": { "odataVersion": "4.0" } } } ...
- Under "sap.ui5" → "models", create a model referencing that data source. For example:
... "models": { "warehouseStockModel": { "dataSource": "warehousePhysicalStockService", "settings": { "groupId": "$direct", "synchronizationMode": "None", "operationMode": "Server" }, "type": "sap.ui.model.odata.v4.ODataModel" } } ...
- Use the new Model in your application.
- Option 1, binding to a View (Declarative Approach, XML). Adjust your XML view file to consider the new model. For example:
... <Table id="myTable" items="{ path: 'warehouseStockModel>/WarehousePhysicalStockProducts', parameters: { $select: 'EWMWarehouse,Product,EWMStockQuantityInBaseUnit,EWMStockQuantityBaseUnit' } }"> ...
- Option 2, accessing the data from Controller's code (Imperative Approach, JavaScript). Adjust your controller code to read data from the new model. For example:
... const oStockModel = this.getOwnerComponent().getModel("warehouseStockModel"); const aFilter = aHUs.map(oHU => { return new sap.ui.model.Filter({ path: "HandlingUnitNumber", operator: sap.ui.model.FilterOperator.EQ, value1: oHU.HandlingUnit }); }); const oHUQIBinding = oStockModel.bindList("/WarehousePhysicalStockProducts", null, // no context null, // no sorters aFilter, { $select: "HandlingUnitNumber,QualityInspectionDocument" } ); oHUQIBinding.requestContexts().then(aContexts => { aContexts.forEach(oContext => { console.log(oContext.getObject()); }); }); ...
Other steps
Depending on your security policies, it is might be required to add the corresponding service to your user catalog or whitelist it. The corresponding steps are not included into this article.
Useful links
- SAP Note 3491952 - Application could not be started due to technical issues. Service group 'XXXX' not published
- SAP Note 2948977 - How to Register OData V4 Service in SAP Gateway System?
Verified systems
- SAP S/4HANA 2023
Provide feedback
If you have comments or suggestions, please feel free to:
- Reply on X/Twitter.
- Leave a comment on our Telegram Channel.