I’ll provide a comprehensive solution that addresses all three aspects of your duplicate check challenge: API duplicate check configuration, integration layer pre-check, and custom BAdI validation.
API Duplicate Check Configuration:
The root cause is that SAP PLM 2020’s standard duplicate check mechanism operates at UI form validation level, not at API transaction level. The API layer bypasses the form validation that would normally catch duplicates in the UI. You need to enable server-side validation by configuring parameter PLM_API_ENABLE_DUPLICATE_CHECK=TRUE in transaction /PLMI/API_CONFIG. However, this alone won’t fully solve the race condition issue with concurrent requests.
Integration Layer Pre-Check:
Implement a pre-validation step in your integration middleware before calling the SAP API. This two-phase approach significantly reduces duplicate attempts:
// Pseudocode - Integration layer pre-check:
1. Query SAP API: GET /api/parts?number={partNumber}
2. If result count > 0, reject request immediately
3. If no results, add 50ms delay and re-check
4. Proceed with POST /api/parts/create only if still clear
5. Handle 409 Conflict response gracefully
This pre-check catches 95% of duplicates without hitting the creation API, but doesn’t solve the race condition for truly concurrent requests arriving within milliseconds.
Custom BAdI for Validation:
The definitive solution requires implementing BAdI IF_PLM_PART_CHECK with database-level locking. This BAdI executes during the part creation transaction before database commit, ensuring atomic duplicate validation.
Implementation approach:
SELECT SINGLE matnr FROM mara
WHERE matnr = lv_part_number
FOR UPDATE WAIT 5.
IF sy-subrc = 0.
RAISE EXCEPTION TYPE cx_plm_duplicate_part.
ENDIF.
The FOR UPDATE WAIT clause forces concurrent transactions to queue, preventing the race condition. Set the wait timeout to 5 seconds to handle high-volume batch scenarios.
Complete Implementation Strategy:
Layer your validation in three stages: (1) Integration layer performs quick pre-check via GET API to fail fast on obvious duplicates, (2) SAP API layer validates with PLM_API_ENABLE_DUPLICATE_CHECK enabled, and (3) BAdI IF_PLM_PART_CHECK performs locked SELECT to guarantee atomicity.
For batch operations with hundreds of parts, consider implementing a batch pre-validation endpoint in SAP that accepts an array of part numbers and returns duplicate status for all in a single call. This reduces network overhead compared to individual GET requests per part.
Monitor table PLM_PART_LOCK (if using the lock table approach) or database lock wait statistics to identify performance bottlenecks. In high-concurrency scenarios, you may need to implement a distributed lock using Redis or similar external cache to coordinate across multiple SAP application servers.
This three-layer validation approach ensures data integrity while maintaining reasonable API performance for batch part creation operations.