cancel
Showing results for 
Search instead for 
Did you mean: 

Help on a UDF

former_member181967
Participant
0 Kudos

Hi,

In my scenario i need to build a UDF for the next structure:

-> Product Code

---> Atribute Code

---> Atribute Value

For each ocurrence of Product Code could occurs n of (Atribute Code + Atribute Value) and as a target i should map this to a string as show in the example:

-> PC - AAA

---> AC - 001

---> AV - QWE

---> AC - 002

---> AV - 12,9

-> PC - BBB

-> PC - CCC

---> AC - 002

---> AV - ZXC

So my target string should remain like this:

AAA;001;QWE;002;12,9|BBB|CCC;002;ZXC|

Can anyone provide me any help regarding the constrution of UDF, as i'm not an expert in java code ...

Thanks in advance,

JMMatos

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

Why you want to write a UDF, you can achieve this with the concat function.

Regards

Stefan

stefan_grube
Active Contributor
0 Kudos

OK, it is not possible with concat, as you want to merge values from the same node and different contexts.

To solve the problem I have defined two UDFs.

The first function merges the values belonging to the same context. Create a function and set the cache to <i>Context</i>.

public void func1(String[] PC,String[] AC,String[] AV,ResultList result,Container container){

String output = PC[0];

 for (int k=0;k<AC.length;k++)
   output = output + ";" + AC[k] + ";" + AV[k];

result.addValue(output);

}

The second function merges the values from different contexts. Create a function and set the cache to <i>Queue</i>.

public void func2(String[] a,ResultList result,Container container){

String output = ""; 

for(int k=0;k<a.length;k++)
   output = output + a[k] + "|";

result.addValue(output);

}

Combine the tags like this:

PC 

AC - func1 - removeContexts - func2 - target

AV /

Regards

Stefan

former_member181967
Participant
0 Kudos

Hi Stefan,

Thanks for your help ...

I've implemented the UDF's as you told me but my structure is a little more complex as i've mentioned before ...

I have a Node1 and my PC above ...

-> Node1

---> PC

Next above PC i have another Node ...

-> Node1

---> PC

-


> Node2

-


> AC

-


> AV

Does it seem to u that those UDF that u have mentioned could be able to work with this structure ?!?!?

Thanks again,

Regards,

JMMatos

stefan_grube
Active Contributor
0 Kudos

Hi José,

The UDF will with your structures as well, when you set the correct context for each element.

If you have:

-> Node1

---> PC

-

-


Node2

-

-


AC

-

-


AV

-

-


Node2

-

-


AC

-

-


AV

Set the context of AC and AV to Node1.

Make sure with Display Queues that all queues have the same number of contexts.

Regards

Stefan

former_member181967
Participant
0 Kudos

Hi Stefan,

Thanks again ... it works nice and pretty !!!

Regards,

JMMatos

Answers (0)