Wednesday, February 23, 2022

Split one field value using groovy script and sent to two output fields in SAP CPI

 Split the value from one input field using space and return to two output fields.


Groovy Scripts:

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

def void ReadNames(String[] ID,Output Fname ,Output Lname,MappingContext context)

{

    def Fname_L = ID[0].substring(0,ID[0].indexOf(' '));

    def Lname_L = ID[0].substring(ID[0].indexOf(' ')+1, ID[0].length())

    Fname.addValue(Fname_L);

    Lname.addValue(Lname_L);

}

(or)

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

def void substring_value(String[] CC, Output output, MappingContext context)

{

String[] list = CC[0].split(" ");

if (list.length > 0)

{

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

{

output.addValue(list[j]);

} }

}


Input-Ramesh Kumar

Output:

First field-Ramesh

Second field-Kumar

No comments:

Post a Comment

The sender will pass the data in JSON format without converting it to XML format. We need to read the particular field.

The sender will pass the data in JSON format without converting it to XML format. We need to read the particular field to check the conditio...