-
Notifications
You must be signed in to change notification settings - Fork 134
SAP S4HANA Inventory Sync
HMIS can fetch goods-receipt records from SAP Materials Management (MM) and compare them against the HMIS pharmacy item master. This helps identify which SAP materials have matching items in HMIS and which do not.
Important: This is an audit sync only. It does not create pharmacy stock entries or GRN (Goods Received Note) records in HMIS. Actual stock intake is handled by the normal HMIS pharmacy GRN workflow.
- HMIS calls the SAP material document API for a date range.
- SAP returns all goods-receipt line items posted in that period.
- For each SAP material number, HMIS looks for a matching pharmacy item by
code(orbarcode, if configured). - The sync returns a summary: how many items matched, how many did not, and the list of unmatched SAP material numbers.
- After a normal forward sync, HMIS updates an internal watermark timestamp so the next sync automatically picks up from where the last one ended.
| Key | Description |
|---|---|
SAP Integration - Enabled |
Must be true
|
SAP Integration - Base URL |
SAP tenant URL |
SAP Integration - Token URL, Client ID, Client Secret
|
OAuth credentials |
SAP Integration - Material Code Field |
Which HMIS item field to match against the SAP material number: code (default) or barcode
|
SAP Integration - Inventory Sync From Days |
When there is no previous sync, how many days back to look. Default: 7
|
SAP Integration - Inventory Last Sync |
Auto-updated timestamp after each successful forward sync. Do not edit manually. |
A forward sync uses the last-sync watermark to automatically determine the start date. If no previous sync has been run, it falls back to the configured number of days ago.
Request
GET /api/sap/inventory/sync
Finance: <api-key>
Supply fromDate and/or toDate to override the automatic date range. The watermark is not updated after a backfill.
Request
GET /api/sap/inventory/sync?fromDate=2024-01-01&toDate=2024-01-31
Finance: <api-key>
{
"status": "success",
"code": 200,
"data": {
"totalDocumentItems": 47,
"matchedItems": 43,
"unmatchedItems": 4,
"syncFromDate": "2024-03-08",
"syncToDate": "2024-03-15",
"lastSyncTimestamp": "2024-03-15T23:59:59",
"unmatchedMaterials": [
"MAT-9001",
"MAT-9002",
"MAT-9003",
"MAT-9004"
],
"warnings": []
}
}| Field | Description |
|---|---|
totalDocumentItems |
Total SAP goods-receipt line items fetched |
matchedItems |
Items that have a matching HMIS pharmacy item |
unmatchedItems |
Items with no match in HMIS |
syncFromDate |
Start date used for the SAP query |
syncToDate |
End date used for the SAP query |
lastSyncTimestamp |
Updated watermark (null for backfill syncs) |
unmatchedMaterials |
List of SAP material numbers with no HMIS match |
warnings |
Any non-fatal issues encountered during the sync |
The watermark (SAP Integration - Inventory Last Sync) ensures that consecutive forward syncs do not re-fetch the same data or leave gaps.
- After a successful forward sync, the watermark is set to the end date of the sync at
23:59:59(the effective SAP upper bound). - The next forward sync starts from the date part of that watermark.
- A backfill (explicit
fromDate) does not update the watermark, so the normal forward sync schedule is not affected.
If SAP material numbers appear in unmatchedMaterials, it means those materials are not yet recorded in the HMIS item master. To resolve this:
- Identify the unmatched material numbers from the sync result.
- Find the corresponding pharmaceutical items in HMIS.
- Set the
codefield (orbarcode, if that is your configured match field) of each item to match the SAP material number. - Re-run the sync — the items should now match.
If most items are unmatched and you are starting fresh, ensure SAP Integration - Material Code Field is set correctly. Contact your system administrator if you are unsure which field to use.
| Problem | What to check |
|---|---|
SAP integration is disabled |
Set SAP Integration - Enabled = true
|
| All items unmatched | Verify SAP Integration - Material Code Field is code or barcode. Confirm HMIS items have the SAP material number in the correct field. |
Warning: Unsupported SAP Integration - Material Code Field
|
The field name is not code or barcode. Correct it in Application Configuration. |
| HTTP 502 error | SAP API returned an error — check Payara server log for details |
totalDocumentItems is 0 |
No goods-receipt documents in SAP for the date range. Try widening the range with explicit fromDate/toDate. |