In SAP CPI Message Mapping, I faced a OneAsMany violation due to mismatched occurrences between two source fields:
Company Code → Occurrence = 1
PRODUCTTAXITEM → Occurrence = 2
So basically, due to difference in context change, I was not able to use it in value mapping where the target field occurrence is also 2 times, due to this if i use it without OneasMany, it is throwing error : target field require value for it.
This resulted in the following OneAsMany rules being violated:
Rule 1: Input 1 should not contain repeating values in the same context.
Business requirement was to:
Increase the context of Company Code
Match it with the number of PRODUCTTAXITEM occurrences
Repeat only the first Company Code value for all PRODUCTTAXITEM contexts.
Groovy code used is as follows:
import com.sap.it.api.mapping.*
// Function name must match the name used in Message Mapping UI
def void replicateCompanyCode(
String[] companyCode,
String[] productTaxItem,
Output companyCodeOut,
MappingContext context) {
// Guard checks
if (companyCode == null || companyCode.length == 0 ||
productTaxItem == null || productTaxItem.length == 0) {
companyCodeOut.addSuppress()
return
}
// Take only the first Company Code
String firstCompanyCode = companyCode[0]
// Create context based on PRODUCTTAXITEM count
for (int i = 0; i < productTaxItem.length; i++) {
companyCodeOut.addValue(firstCompanyCode)
companyCodeOut.addContextChange()
}
}
Unit test :
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 35 | |
| 10 | |
| 9 | |
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 3 |