Skip to Content
0
Aug 29, 2023 at 04:11 PM

SAP CPI - Groovy script logic for CompanyCode lookup

150 Views Last edit Aug 29, 2023 at 05:36 PM 4 rev

Hello Experts,

Need Your help for a logic,
I have two input structures (merged) - one with the Record nodes and other one is used for lookup which has Company code & Network IDs.

Logic - Lookup is done on //Record/CompCodes/CompanyCode and //select_response/row/Child_Company_Code

If both of the above values match, then return the respective //select_response/row/Child_Node_Network

(Network IDs can be duplicate)

example.png

image.png

I am able to lookup the Network IDs but not able to manage the Context and break the output in separate nodes.

CPI Input - cpi-second-map-input-multiple-company-codes.xml

Wrong Output - cpi-wrong-output-giving-only-1-company-code.xml

Desired output - cpi-second-map-output-multiple-company-codes.xml

-------------------------------------------------------------------------------------------------------------------------------------------------
Groovy Script I have used -

import com.sap.it.api.mapping.*;

def void lookup(String[] Parent_Company_Code, String[] Child_Company_Code, String[] Child_Node_Network, Output output, MappingContext context) {

String a = "";

for(int i=0; i<Parent_Company_Code.length; i++) {

for(int j=0; j<Child_Company_Code.length; j++) {

if(Parent_Company_Code[i] == null || Child_Company_Code[j] == null)

continue;

if(Parent_Company_Code[i].equals(Child_Company_Code[j])) {

a = Child_Node_Network[j];

//break;

output.addValue(a);

}

}

}

//output.addValue(a);

}

-------------------------------------------------------------------------------------------------------------------------------------------------

Thanks,

Akshay