cancel
Showing results for 
Search instead for 
Did you mean: 

UDF - loop and context change

05-08-2020 4:19 AM
SAP Managed Tags
Subscribe

Hi PI/PO Experts,

I have been trying with UDF with no luck, so reaching for your expertise

Requirement is simple : when source has value 1 then target should have value 1 in same context

When source has 1 and below value is 2 which is in separate context then target should have values 1 and 2 in same context and similarly source has 1,2,3 in separate context the target should have 1,2,3 in same context as shown below

Please share an UDF if you have one to achieve the requirement

Accepted Solutions (1)

Accepted Solutions (1)

former_member190293
Active Contributor
0 Likes

Hi!

In order to remove initial context change try to check the index of item being processed. If it's the very first item in the queue (i == 0) - you shouldn' add context change.

Regards, Evgeniy.

Answers (3)

Answers (3)

Former Member
0 Likes

Hi,

Below code works as expected however i see an extra <null> occur due to which the context is changing, so how do i remove the null with in the code

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

public void cc1(String[] input, Output output, MappingContext context) {
for (int i = 0; i < input.length; i++)
{
if ((input[i].equals("1")) )

{
output.addContextChange();
output.addValue(input[i]);
// result.addValue(ResultList.CC);
}
else {

output.addValue(input[i]);

}
}
}

Former Member
0 Likes

Hi,

Thank you for helping here

My code is getting wrong results

I am expecting below code to add context change but getting wrong results

for (int i = 0; i < input.length; i++)
{
if (input[i].equals("1"))
{
result.addValue(input[i]);
result.addContextChange();
}
else {
result.addValue(input[i]);
}
}

former_member190293
Active Contributor
0 Likes

Hi!

Wouldn't you please provide your UDF code?

Regards, Evgeniy.