on 09-08-2011 9:59 AM
Hi all,
I have a complicated requirement. I need to reorder contexts/ values.
Example:
<parent>
<child>2</child>
</parent>
<parent>
<child>51</child>
</parent>
<parent>
<child>14</child>
</parent>
<parent>
<child>32</child>
</parent>
Output of this input will be:
2
51
14
32
I need it to be:
32
51
2
14
I cannot use sort or sortbykey since there is no ascending or descending order.
Thanks in advance.
Regards,
SAPEnthusiast
Hi,
Can you please provide occurences of the source and target structure.
Thanks,
Enivass
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm really sorry to those who replied. There were not enough details.
Ok here's a clear example:
<parent>
<child>X</child>
</parent>
<parent>
<child>A</child>
</parent>
<parent>
<child>B</child>
</parent>
<parent>
<child>Y</child>
</parent>
there's a rule that X=1, A=2, B=3, Y=4
In my current mapping, output is:
1,2,3,4
I need it to be
3,4,2,1
The order of the source is not fixed. It can be A,B,X,Y or X,B,A,Y.. etc.
The order of the target is fixed. B,Y,A,X (3,4,2,1).
Ok I'll just follow your suggestion a while ago. Thanks for that
But I have a new problem now Sorry I noticed just now..
The other fields should be sorted according to the rule I stated before.
Example:
<parent>
<child>X</child>
<detail1>dog</detail1>
<detail2>car</detail2>
<detail3>wood</detail3>
</parent>
<parent>
<child>A</child>
<detail1>cat</detail1>
<detail2>bus</detail2>
<detail3>metal</detail3>
</parent>
<parent>
<child>B</child>
<detail1>frog</detail1>
<detail2>van</detail2>
<detail3>cotton</detail3>
</parent>
<parent>
<child>Y</child>
<detail1>rabbit</detail1>
<detail2>train</detail2>
<detail3>plastic</detail3>
</parent>
Aside from:
3
4
2
1
It should also be:
3 frog van cotton
4 rabbit train plastic
2 cat bus metal
1 dog car wood
<targetnode>
<targetfield>3</targetfield>
<targetfield2>frog</targetfield>
<targetfield3>van</targetfield>
<targetfield4>cotton</targetfield>
</targetnode>
<targetnode>
<targetfield>4</targetfield>
<targetfield2>rabbit</targetfield>
<targetfield3>train</targetfield>
<targetfield4>plastic</targetfield>
</targetnode>
<targetnode>
<targetfield>2</targetfield>
<targetfield2>cat</targetfield>
<targetfield3>bus</targetfield>
<targetfield4>metal</targetfield>
</targetnode>
<targetnode>
<targetfield>1</targetfield>
<targetfield2>dog</targetfield>
<targetfield3>car</targetfield>
<targetfield4>wood</targetfield>
</targetnode>
Right now, the output is
3 dog car wood
4 cat bus metal
2 frog van cotton
1 rabbit train plastic
UDF1: i have taken this code from Debashish's reply
public void Rearrange(ResultList result, Container container) throws StreamTransformationException
{
result.addValue("B");
result.addValue("Y"]);
result.addValue("A");
result.addValue("X");
}
UDF2: will have 3 inputs of type string
Execution type: all values of a context.
int a=var1.length;
int b= var2.length;
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
if(var1<i>.equals(var2[j]))
{
result.addValue(var3[j]);
break;
}
}
}
Mapping:
UDF1----
child---remove context
detail1---remocecontext--
UDF1----
child---remove context
detail2---remocecontext--
in the same way proceed for the rest of the fileds
Hi
Use below UserDefined Function
public void Rearrange(String[] input, ResultList result, Container container) throws StreamTransformationException
{
result.addValue(input[3]);
result.addValue(input[4]);
result.addValue(input[1]);
result.addValue(input[2]);
}
Thanks
Mary Durai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Use below Userdefined Function.
public void Rearrange(String[] input, ResultList result, Container container) throws StreamTransformationException
{
result.addValue(input[3]);
result.addValue(input[1]);
result.addValue(input[0]);
result.addValue(input[2]);
}
Thanks
Mary Durai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if the sequence is fixed then u can go for CopyValue function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You have not mentioned the logic based on which you are re ordering the contexts.
However, if its a fixed order, you can handle this in a UDF (queue) function. The input argument would child field.
In the UDF, you can search for the values in order and output them to the resultList.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Use this UDF
public void Rearrange(String[] input, ResultList result, Container container) throws StreamTransformationException
{
result.addValue(input[3]);
result.addValue(input[1]);
result.addValue(input[0]);
result.addValue(input[2]);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.