There may be requirement in our development that we are obstructing any value from the queue to be populated on the target side. In this scenario we need to obstruct values of other corresponding nodes with respect to obstructed node value coming at same level. Below UDF will help in attaining this requirement.
Example: We are getting multiple Name and Age under Student Node. We want to remove particular Name. Hence we must remove Age corresponding to that name to avoid inconsistency.
Below code will help for the same:
Step1: Create a user defined function as below. Take input as All vales of queue if you want to handle at queue level else take as All values from Context. My requirement was at queue levele so I took the same.
Step 2: Write the below code:(Suppose we want to block CIS coming in first queue and its corresponding values in second queue/context).
ArrayList <String> al = new ArrayList<String>(Arrays.asList(var1));
ArrayList <String> al1 = new ArrayList<String>(Arrays.asList(var2));
ArrayList <String> al1 = new ArrayList<String>(Arrays.asList(var2));
if(al.contains("CIS")){
int ind = -1;
for (int i =0;i<var1.length; i++){
if(var1[i].equals("CIS"))
ind = i;
}
al.remove(ind);
al1.remove(ind);
String str1[] = new String[al.size()];
String str2[] = new String[al.size()];
for (int i = 0; i<al.size();i++)
{
str1[i]= al.get(i);
str2[i]= al1.get(i);
}
for (int j =0; j< al.size(); j++){
result.addValue(str1[j]);
}
}else {
int ind = -1;
for (int i =0;i<var1.length; i++){
if(var1[i].equals("CIS"))
ind = i;
}
al.remove(ind);
al1.remove(ind);
String str1[] = new String[al.size()];
String str2[] = new String[al.size()];
for (int i = 0; i<al.size();i++)
{
str1[i]= al.get(i);
str2[i]= al1.get(i);
}
for (int j =0; j< al.size(); j++){
result.addValue(str1[j]);
}
}else {
for (int j =0; j< var1.length; j++){
result.addValue(var1[j]);
}
}
result.addValue(var1[j]);
}
}
Step3: Now map the first field in first input and second field in second input and use split by each value node function.
Step4 : Do the same for every node coming at same level.
Hi,
ReplyDeleteRahul..
Its good to hear from u that u r good at udfs and java mapping...im new to sap pi and was not good in udfs and java mapping could u pls help me with some scenarios using udfs and java mapping..please help me with this..
Thanks in advance