Great questions from both of you. Let me provide comprehensive details on our implementation:
SAP-to-MES API Mapping:
We created a detailed mapping specification covering these key areas:
Production Order Header:
SAP Field → MES Field
AUFNR (Order Number) → workOrderNumber
MATNR (Material) → productCode
GAMNG (Order Quantity) → targetQuantity
GSTRPGLTRP (Dates) → scheduledStartDate, scheduledEndDate
WERKS (Plant) → facilityCode
Operation Details:
SAP operations (AFVC table) map to MES routing steps. Key transformation:
- SAP operation number (0010, 0020) → MES sequence (1, 2, 3)
- ARBPL (Work Center) → MES resourceCode
- VORNR (Operation) → operationCode
- VGW01-VGW06 (Standard values) → setupTime, runTime, teardownTime
Material Components:
SAP BOM components (RESB table) → MES material requirements:
- MATNR → materialCode
- BDMNG → requiredQuantity
- LGORT → storageLocation
- RSPOS → bomPosition (for sequencing)
Automated Polling Mechanism:
Our integration service architecture:
- Polling Schedule: Runs every 5 minutes via scheduled task
- SAP Query: OData service call to retrieve orders:
GET /sap/opu/odata/sap/API_PROD_ORDER_SRV/
ProductionOrder?
$filter=ReleasedDate ge '2024-12-16T13:00:00'
and Status eq 'REL'
$expand=Operation,Component
- Change Detection: Maintains state table tracking last processed timestamp and order versions
- Batch Processing: Groups orders into batches of 20 for efficient MES API calls
- Connection Pooling: Maintains 5 persistent SAP OData connections to avoid overhead
Performance metrics:
- Average SAP query time: 800ms for 10 orders
- MES work order creation: 200ms per order
- Total cycle time: 2-3 seconds for typical batch
Status Synchronization:
Bidirectional status flow implementation:
MES → SAP (Operation Confirmations):
When operators perform actions in MES:
- Start operation → POST to SAP BAPI_PRODORDCONF_CREATE_HDR
- Complete operation → Confirmation with actual quantities/times
- Report scrap → Confirmation with scrap quantity and reason code
Pseudocode for status sync:
// Pseudocode - MES to SAP status synchronization:
1. MES triggers operation status change event
2. Integration service listens to MES event queue
3. Transform MES operation data to SAP confirmation format:
- Map MES operationId to SAP order/operation numbers
- Convert quantities and timestamps
- Add confirmation type (START/FINISH/SCRAP)
4. Call SAP BAPI with confirmation data
5. Handle SAP response and update MES with confirmation number
6. Log transaction for audit trail
// Retry logic: 3 attempts with exponential backoff
Handling Operation Splits/Combines:
We prevent this issue by configuration:
- MES operations are locked once dispatched (no split/combine allowed)
- If operational changes needed, supervisor cancels MES work order and requests SAP change
- SAP engineering change triggers new dispatch cycle
- This maintains single source of truth in SAP
Error Handling and Retry Logic:
Multi-tier error handling strategy:
Tier 1 - Transient Errors:
- Network timeouts, temporary API unavailability
- Retry: 3 attempts with delays of 30s, 2min, 5min
- Success rate: 95% resolve within retries
Tier 2 - Persistent Queue:
- Failed orders move to persistent queue (PostgreSQL)
- Background process retries every 10 minutes
- Alerts triggered if queue depth >50 or age >2 hours
Tier 3 - Manual Intervention Queue:
- Data validation failures (missing materials, invalid work centers)
- Orders flagged for supervisor review in dashboard
- Supervisor can correct data and re-dispatch
Edge Case Handling:
Rush Orders:
- SAP priority field maps to MES priority
- High-priority orders (priority <10) polled every 2 minutes instead of 5
- MES scheduling algorithm automatically prioritizes
Engineering Changes:
- SAP change number (AENNR) tracked in integration state
- If change detected on existing order, MES work order marked obsolete
- New work order created with revised routing/BOM
- In-progress operations allowed to complete before transition
Material Shortages:
- Integration queries SAP material availability (BAPI_MATERIAL_AVAILABILITY)
- If shortage detected, work order dispatched but flagged “Material Hold”
- MES displays material shortage alert to supervisors
- Automatic re-check every 30 minutes until materials available
Implementation Results:
Quantitative Benefits:
- Manual data entry time: 45-60 min/shift → 5-8 min/shift (85% reduction)
- Transcription errors: 12-15 per week → 0-1 per week
- Work order dispatch delay: 2-4 hours → 5-10 minutes
- Production visibility: End-of-shift → Real-time
Operational Improvements:
- Supervisors focus on exception management vs. data entry
- Real-time SAP updates enable better production scheduling
- Reduced phone calls between planning and production (70% reduction)
- Material staging accuracy improved (advance notice of requirements)
Technical Stack:
- Integration Service: Java Spring Boot application
- SAP Connectivity: OData v2 client library
- MES Connectivity: REST client with connection pooling
- Message Queue: RabbitMQ for event handling
- State Database: PostgreSQL for tracking and retry queue
- Monitoring: Prometheus + Grafana dashboards
- Deployment: Docker containers on Kubernetes
Lessons Learned:
- Invest heavily in data mapping documentation upfront
- Implement comprehensive logging for troubleshooting
- Build monitoring dashboards before go-live
- Plan for gradual rollout (we did 1 production line at a time)
- Train supervisors on exception handling before automation
The key to success was treating this as a business process transformation, not just a technical integration. We involved operations, planning, IT, and quality teams throughout the design phase to ensure the automation truly addressed their pain points.