cancel
Showing results for 
Search instead for 
Did you mean: 

Value Mapping: how to loop over a nested context in a adv. user function

Former Member
0 Kudos

Hello,

i have the following source structure:

<rec> (1:1)

<field1>aaa</field1> (1:1)

<field2>bbb</field2> (1:1)

<b><struc> <u>(1:unbounded)</u>

<name>myName</name>

<value>myValue</value>

</struc></b>

</rec>

Destination structure:

<rec> (1:1)

<field1>aaa</field1> (1:1)

<field2>bbb</field2> (1:1)

<b><field3>bbb</field2> (1:1)</b>

</rec>

In order to fill the destination field3 i have to loop over the input-structure struc.

My problem is, that i don't know how to get access to the name/value pair with a

extended user-defined function. Since each occurrence in struc i not a simple string but consists of 2 fields, i guess it is not enough simply to loop over input String Array.

Please help.

Accepted Solutions (1)

Accepted Solutions (1)

prabhu_s2
Active Contributor
0 Kudos

just like u have a loop stmt in java prgm. a simple code:

Here a and b are the strings that comes to the udf

for(int i=0;i<a.length;i++)
{
	boolean found = false;
	int j = 0;
	for(j=0;j<b.length;j++)
	{
		if (a<i>.equals(b[j]))
		{
			found = true;
			break;
		}
	}
	if (found == true)
		result.addValue(c[j]);
	else
		result.addValue("");
}

Message was edited by:

Prabhu S

Former Member
0 Kudos

Thank you so far.

Unfortunately i'm not a java expert... What i do not understand:

in your example 'a' is the input string array of the function. This input array has

<struc> as input according to my example. Thus for each iteration 'a' consists of the next occurence of the pair <name> and the <value>. But how to get access to them? How can i tell the function that 'a' is a another string array consisting of <name> as index 0 and <value> as index 1? Where do 'b' and 'c' come from in your example?

prabhu_s2
Active Contributor
0 Kudos

<b>struc</b> will be <b>a</b>. and looping into <b>struc</b> will fetch the value for the fields under <b>struc</b>

<b>Where do 'b' and 'c' come from in your example?</b>

it is just a piece of code what i had used earlier in my scenario...hence not customized to ur post

Message was edited by:

Prabhu S

henrique_pinto
Active Contributor
0 Kudos

I guess it'd be easier if the input of ur UDF was Name and a RemoveContexts function:

Name - RemoveContexts - UDF - field3

ur UDF could be simpler, I guess:

for (int j = 0; j < a.length; j++) {
    if (a[j].equals("<any_specific_name>"))
        return "true";
}
return false;

Regards,

Henrique.

Former Member
0 Kudos

Fine, thank you.

henrique_pinto
Active Contributor
0 Kudos

Actually you will have to make some changes on that, cause you won't return a string but a ResultList. But that's the main idea.

for (int j = 0; j < a.length; j++) {
    if (a[j].equals("<any_specific_name>")) {
        result.addValue("true");
        break;
    }
}
result.addValue("false");

Regards,

Henrique.

Answers (0)