Integration Blog Posts
cancel
Showing results for 
Search instead for 
Did you mean: 
Deepak_Khani07
Discoverer
0 Likes
401

Problem Statement

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 :

    contextincrease.png