on 06-01-2007 8:23 AM
Hi all,
I have a problem with my UDF. <i>A break statement doesnt break out of the for loop. </i>Please go thru the follwing and offer your helping hand.
<b>The Issue:</b>
In need to <i>check the value of a "child" element for each occurrence of the parent node </i>and if the condition is true then <i>map the value of "1" to the target element </i>with the same name and a same parent.
<b>Source Structure:</b>
ParentNode1 <1..1>
...Child Node1 <1.unbounded>
.... Flag_Source <1.1>
<b> Target Structure</b>
ParentNode1 <1..1>
....Child Node <1. unbounded>
Flag_Target <1.1.> Mapping
<b>GUI Mapping: </b>
(Flag Source) -
[UDF]>>>>>>FlagTarget
^-
(ChildNode1) -
^
<b>Condition:</b>
for each child node1
If ParentNode1>ChildNode1>FlagSource = 1
then Flag-Target = 1
<b>Global Integer Element flag</b>
int flag;
<b>UDF:</b>
<i>Info:</i> Type is Context;
Takes 2 Arguments
1. Flag_Source- <i>Context Set to ParentNode</i>
2.ChildNode1
AbstractTrace trace = container.getTrace();
for ( int j = 1; j < ChildNode1.length; j++)<i>
{
if ( Flag_Source[j].equals(" 1")){
trace.addInfo("retrieved the value"+Flag_Source[j]);
flag = 1;
break; <b>// the for loop does not terminate here</b>
}else
{
flag= 0;
}
}
if ( flag == 1) {
result.addValue("1");
}
else
{
result.addValue("0");
}
<b>Testing</b>
Also when i test the mapping , I get the following error
<b>
"Cannot produce target element..
Check xml instance is valid for source xsd and target-field mapping fulfills..."</b>
Please help me with your suggestions
Thanks
regards
krishna
Hi All
I have gone through both the solutions. Mudit has provided a right one but I would suggest that it ll affect the performance as the loop will run up till the end although the value "1" is encountered in between.
Follow this logic. i think it helps.
for ( int j = 1; j < ChildNode1.length; j++)
{
if ( Flag_Source[j].equals(" 1")){
trace.addInfo("retrieved the value"+Flag_Source[j]);
result.addValue("1");
exit(0);
}else
{
result.addValue("0");
}
}
Thanks
Amit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amit,
Your logic is right.But i do not understand about "exit(0)".When i implement exit(0) my system gives
<b>cannot resolve symbol symbol : method exit (int) location: class com.sap.xi.tf._XX_XXXX_ exit(0); ^ 1 error</b>
Do you explain this?
We have a blog that gives us concept about System.exit(0)
<u>/people/sap.user72/blog/2005/12/08/don146ts-in-exchange-infrastructure
Cheers!
Samarjit
Hi all,
I have successfully mapped the source to the target.
I was working simultaneously on the issue. I just saw your responses and i appreciate all of your feedback.
Mudit,
As per your soultion, I would not achieve the desire result because I need to read the value of "flag_source" for every instance of childnode1 and i can only achieve this by havin
ffor(int i=0; i< childnode1.length;i++) and not flagnode.length as you have suggested.
Samarajit,
Nice observation about the blanks space:) but you know what I spent a lot of time just to figure that there was a blank comming up before 1:)
Amit,
Your solution closely matches up my "Working" function though I had to fix some context related issues. I used "SplitByValue"for that .
Thank you all again for your inputs
Regards
krishna
Hi Krish,
In your code i found a blank space...remove that and run UDF again...Thats why can not entered the loop.
>> if ( Flag_Source[j].equals(" 1"))
if ( Flag_Source[j].equals("1"))
>>for ( int j = 1; j < ChildNode1.length; j++)
why you staring with j=1?It should be j=0
for ( int j = 0; j < ChildNode1.length; j++)
Cheers!
Samarjit
Message was edited by:
Samarjit Dey
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi;
You mean to say that if under any of your child nodes if flag has value 1 then you have to map 1 to the target flag node.
One question is target flag node has a single occurance or its under child node.
Use this UDF
Type context
Input flagnode(contxt set to parent)
int count =0;
for(int i=0;i<flagnode.length;i++)
{
if(flagnode<i>.equals("1"))
{
count++;
}
}
if(count>0)
{
result.addValue("1");
}
else
{
result.addValue("0");
}
Mudit
Award points if it helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
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.