cancel
Showing results for 
Search instead for 
Did you mean: 

grouping and handling context using UDF

Former Member
0 Kudos

Hi Guys,

I have a requirement where i am getting two queues as input.

In first queue i am getting value like 10,20,30,40,70,80.

And in second queue i am getting value like 10,10,20,20,20,20,30,40,80

I have to take value from first queue and need to compare from second queue,

Whenever i get equal value I need to group them and insert a context change in between

my desired output is

10,10<contextchange>20,20,20,20<contextchange>30<contextchange>40<contextchange>null,80<end of queue>

i.e. If there is no value for a value at first queue i need to return null for them

for this i have a written a UDF which is working fine but returning a extra null at the end,

Codeu2014

int i=0;

while(i<var1.length)

{

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

{

if(var1<i>.equals(var2[j]))

{

result.addValue(var1<i>);

}

}

result.addContextChange();

i=i+1;

}

I am getting extra null after ---80, null<end of queue>

Can any buddy help me that why i am getting a extra null at the end.

Thanks

Navneet

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Navneet

Before adding a context change check that you have not reached the end of the queue:

if(i < var1.length-1){
	result.addContextChange();
}

I think that in the following 2 lines

if(var1.equals(var2[j]))

result.addValue(var1);

var1 should be replaced with

var1<i>

Regards,

Giuseppe

Answers (1)

Answers (1)

Former Member
0 Kudos

Agree with Giuseppe above. Change your while clause to

while(i<var1.length-1)

For the last element, add the below lines of code :

for(int j=0;j<var2.length;j++)
{
if(var1[var1.length-1].equals(var2[j]))
{
result.addValue(var2[j]);
}
}

add the above snippet after your code.

Former Member
0 Kudos

we have solved the problem using below code.

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

{

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

{

if(var1<i>.equals(var2[j]))

{

result.addValue(i);

}

}

result.addContextChange();

}

result.addSuppress();

}

Adding a Suppress at the end .

it is suppressing the Last null and giving me a colored SUPPRESS.

Regards,

Navneet