Here’s a comprehensive solution addressing rollback logic, savepoint management, and change notification handling:
1. Rollback Logic Redesign
The fundamental issue is that traditional database rollback doesn’t work reliably with SAP PLM’s long-running ECN workflows due to auto-commits and transaction boundary complexities. Implement a compensation-based approach:
State Tracking Table:
CREATE TABLE ECN_WORKFLOW_STATE (
ecn_id VARCHAR2(50),
stage_name VARCHAR2(100),
stage_status VARCHAR2(20),
completed_at TIMESTAMP,
rollback_required CHAR(1)
);
2. Savepoint Management Alternative
Since savepoints don’t survive commits and ECN workflows auto-commit, replace savepoint-based rollback with explicit compensation logic:
// Pseudocode - Compensation pattern implementation:
1. Record workflow stage entry in ECN_WORKFLOW_STATE table
2. Execute stage operations (item updates, approvals, etc.)
3. Mark stage as COMPLETED in state table with commit
4. If error in subsequent stage, read state table
5. Execute stage-specific compensation methods in reverse order
6. Mark stages as ROLLED_BACK in state table
// See ECN Workflow Guide Section 12.3 for compensation handlers
Each ECN workflow stage needs a corresponding compensation handler:
- ITEMS_UPDATED stage: Compensation reverses affected item associations
- APPROVALS_CREATED stage: Compensation cancels pending approvals and removes approval records
- NOTIFICATIONS_SENT stage: Compensation sends cancellation notifications
- BOM_UPDATED stage: Compensation restores previous BOM revision
3. Change Notification Handling
Implement robust change notification state management:
Immediate Actions:
- Create a cleanup utility to identify orphaned change notifications:
SELECT ecn.ecn_id, ecn.status, ews.stage_name
FROM ECN_MASTER ecn
LEFT JOIN ECN_WORKFLOW_STATE ews ON ecn.ecn_id = ews.ecn_id
WHERE ecn.status = 'IN_PROGRESS'
AND NOT EXISTS (
SELECT 1 FROM ECN_WORKFLOW_STATE
WHERE ecn_id = ecn.ecn_id
AND stage_status = 'COMPLETED'
AND completed_at > SYSDATE - 1
);
- Add a scheduled job that runs every 4 hours to detect and flag stuck change notifications for manual review
Long-term Architecture:
- Implement idempotent operations for all ECN workflow stages so they can be safely retried
- Add optimistic locking with version numbers to prevent concurrent modification conflicts
- Create a workflow audit trail that logs every state transition with before/after snapshots
- Configure workflow timeout thresholds - if an ECN stage exceeds 30 minutes without progress, auto-trigger compensation
Configuration Changes:
- Increase UNDO tablespace retention: `ALTER SYSTEM SET UNDO_RETENTION = 3600 SCOPE=BOTH;
- Disable auto-commit for ECN-specific workflows in your application server configuration
- Set transaction isolation to READ_COMMITTED with row-level locking
- Configure connection pool with proper transaction timeout settings (aligned with workflow duration)
Error Recovery Procedure:
- When rollback fails, immediately log the ECN_ID and current workflow state
- Execute the compensation handler chain in reverse stage order
- Update change notification status to ‘ROLLBACK_COMPLETED’ or ‘REQUIRES_MANUAL_REVIEW’
- Send automated notification to change managers with recovery details
- Use Flashback Query for data verification: `SELECT * FROM ECN_MASTER AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL ‘1’ HOUR)
This compensation-based approach eliminates dependency on database savepoints and provides explicit control over each stage’s reversal logic, significantly improving reliability for complex ECN workflows in SAP PLM 2020.