on 07-19-2013 5:41 PM
Hi,
In source there is field A - which has 3 values X,Y,Z
In target there is a field B
I need a UDF -
If A=X ,B=R
If A=Y, B=R1
If A=Z, C= R2
Can any one share UDF code or send screenshot for it. Thanks.
Hi SAP,
you can achieve this using fix value function as mentioned by Ambrish Mishra.
no need to go for udf. any reason why do you want UDF?
do the mapping something like this.
FieldA-->fixvalues-->FieldB.
Regards,
Muniyappan..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need a UDF -
If A=X ,B=R
If A=Y, B=R1
If A=Z, B= R2
the requirement is actually this, please advise on it :
actually under element A there is attribute M which will have dynamic value and that dynamic value will be passed to element B.. (R,R1,R2 are dynamic values which will come from attribute M values)
X,Y,Z are constant but conditions will be on attribute M dynamic values.
sorry i wasn't clear earlier...
hi,
thanks 4 ur reply.
I am attaching word document giving input xml file and desired output. there r 3 cases in it of input data.
pls provide help for UDF in it.
rgds
Case 1 : When Firstvalue is
present (irrespective of firstvalue present or not).
<Element1>
<AllOne dom="Firstvalue">
<Id>FirstvalueValue</Id>
<AllOne dom="onefirstvalue">
<Id>xyz</Id>
</AllOne>
<AllOne dom="sap">
<Id>klm</Id>
</AllOne>
<AllOne dom="firstvalue">
<Id>xyz</Id>
</AllOne>
<AllOne dom="SID">
<Id>klm</Id>
</AllOne>
</Element1>
Output
--------------------------------------------------
<Element1>
<AllOne dom="Firstvalue">
<Id>FirstvalueValue</Id>
</AllOne>
</Element1>
Case 2 : When Firstvalue is
not present and firstvalue is present.
<Element1>
<AllOne dom="onefirstvalue">
<Id>xyz</Id>
</AllOne>
<AllOne dom="sap">
<Id>klm</Id>
</AllOne>
<AllOne dom="firstvalue">
<Id>smallfirstvalue</Id>
</AllOne>
<AllOne dom="SID">
<Id>klm</Id>
</AllOne>
</Element1>
---------------------------------------------------------------------------
Output
--------------------------------------------------
<Element1>
<AllOne dom="Firstvalue">
<Id> smallfirstvalue </Id>
</AllOne>
</Element1>
Case 3 : When Firstvalue
and firstvalue both are not present.
<Element1>
<AllOne dom="onefirstvalue">
<Id>novalue</Id>
</AllOne>
<AllOne dom="sap">
<Id>klm</Id>
</AllOne>
<AllOne dom="SID">
<Id>klm</Id>
</AllOne>
</Element1>
---------------------------------------------------------------------------
Output
--------------------------------------------------
<Element1>
<AllOne dom="Firstvalue">
<Id> novalue </Id>
</AllOne>
</Element1>
---------------------------------------------------------------------------
Hello,
Check below UDF:
Execution type: all values of a context
Input: var1, var2
ResultList: result1, result2
int count1=0;
int count2=0;
String value1="";
String value2="";
for (int i=0;i<var1.length;i++)
{
if(var1[i].equals("Firstvalue"))
{
value1=var2[i];
count1=count1+1;
break;
}
if(var1[i].equals("firstvalue"))
{
value2=var2[i];
count2=count2+1;
continue;
}
}
if(count1>0)
{
result1.addValue("Firstvalue");
result2.addValue(value1);
}
else if(count2>0)
{
result1.addValue("firstvalue");
result2.addValue(value2);
}
else
{
result1.addValue("Firstvalue");
result2.addValue(var2[0]);
}
Mapping: Do remember to change the context of both id and dom and set it to "Element1" level
Thanks
Amit Srivastava
Hi,
I would suggest a simple mapping for this requirement.
I have tested with your test cases and it works fine.
context of @dom and Id is root node (Element1 in your case)
I just used a simpler data type.
UDF code:
Parameters: DOM, ID
______________________________________
String temp = "";
for (int i= 0; i<DOM.length ; i++)
if(DOM[i].equals("FirstValue")){
temp = ID[i];
break;
}
else if(DOM[i].equals("firstvalue")){
temp = ID[i];
break;
}
else
temp = ID[0];
result.addValue(temp);
______________________________________
Hope this works for you.
Ambrish
Your requirement is much clear after you explained your test cases well :) Message was edited by: Ambrish Mishra
Hi,
Thanks Amit & Ambrish. Both the solutions are working fine
Rgds
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need a UDF -
If A=X ,B=R
If A=Y, B=R1
If A=Z, B= R2
actually under element A there is attribute M which will have dynamic value and that dynamic value will be passed to element B.. (R,R1,R2 are dynamic values which will come from attribute M values)
X,Y,Z are constant but conditions will be on attribute M dynamic values.
sorry i wasn't clear earlier...
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
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.