cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting a string(Input) and assigning to different fields in a target using UDF(Dynamic Substring)

0 Kudos

Hello everyone,

I am naive in SAP PI and not ready to deal with UDFs strongly.

I have requirement of splitting an input string and assign to the target field. I tried to achieve this using graphical mapping function SUBSTRING and working fine. But want to do this dynamically using UDF. Please can I get the logic code for UDF.

E.g Input="123456778822337654341234567788123456" Result should be as below:

Output

<input>

<input>

<Item1>1234567788</Item1>

</input>

<Header2>

<Item2>2233765434</Item2>

</Header2>

<Header2>

<Item2>1234567788</Item2>

</Header2>

<Header2>

<Item2>123456</Item2>

</Header2>

</input>

Anticipating positive response.

Thanks and regards,

Krushna Band

Accepted Solutions (1)

Accepted Solutions (1)

manoj_khavatkopp
Active Contributor

Hi Krushna ,

Try the below code :

Set Execution type as All value of Context. Aurgument for input : inp.

     String message = inp[0];
		int len = 10;
		for (int i = 0; i < message.length(); i += len) 
		{
		 result.addValue(message.substring(i, Math.min(i + len, message.length())));
                 result.addValue(ResultList.CC);
		}


Result :

Thanks,

Manoj K

0 Kudos

Thank you for the response. Got the logic.

Krushna Band

0 Kudos

Considering the headers at the target, need to change the code accordingly.

Krushna Band

Answers (0)