on 11-12-2010 8:14 PM
Hi all,
I am looking for UDF to perform the following logic, please help me
I will have 3 inputs, say field1, fields2, field3. If field1 = field2 then return field3.
You may say that this can be implemented by message mapping with IF condition itself. But here field1 & field2 are from different segments.Field1 & field3 are from same segment.
When i use message mapping because of this context problems, i am able to get this validation for the first set only.
If i have the multiple values means, i am not able to get it.
all these field1, field2 & field3 are multiple times
Regards
Suman gupta
Execution Type: Queue
3 inputs: field1, field2, field3
for(int i =0;i<field1.length;i++)
{
if(field1<i>.equals(field2<i>))
{
result.addValue(field3<i>);
}
Hope it helps!
raj.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Raj,
Thanks for reply.
I am getting the error as
The message is: Exception:[java.lang.ArrayIndexOutOfBoundsException: 2] in class com.sap.xi.tf._MM_Shipment_method STOP_Validation$[, , ]
This is my mapping, i set all 3 input context to same level.
http://img593.imageshack.us/img593/4681/60467858.jpg
Regards
Chirag,
I set the all 3 input's context to parent level and now error is not there.which is fine
But i am not getting output even though field1 & field2 are equal/
The logic should be in this way.
Record1:
ABC(segment)
<Field2>01</field2>
<Field1>20101110</field3>
XYZ(segment)
<Field1>10</field1>
Record2:
ABC(segment)
<Field2>10</field2>
<Field1>20090909</field3>
XYZ(segment)
<Field1>01</field1>
In the above case Record1-field1 should check whether Record1-field1==Record1-field2 ?? NO
Record1-field1==Record2-field2?? YES the return 20090909
And
Record2-field1 should check whether Record2-field1==Record2-field2 ???? NO
Record2-field1==Record1-field2 ??? YES then return 20101110.
Please let me know, i am not able to achieve this using graphical Mapping, thats why i am thinking about UDF.
Regards
Hi Suman,
can you post here a sample xml structure that you are using for mapping? The sample must contain multiple segments with all fields appearing multiple times. I would also like to see the target xml sample structure. Please mention the number of times each field might appear both in source and target structure.
regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suman,
As suggeted by other members of this forum you must try graphical mapping as far as possible. I am also trying your case. But this is very easily solved using java mapping. You just have to use DOM parser (or other parser). If you call execute method of it passing the input messages structure and expected output structure. Within execute method you can access individual fields of the source message and generate target structure in the maner you want. In your case you only have to check whether field1 is equal to field2 and create a field called field3 in target XML. you can refer to this tutorial for java mapping http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/
Java mapping should be the last resort to solve mapping problems, but using DOM parser we can solve the most critical of mapping problems.
regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When i use message mapping because of this context problems, i am able to get this validation for the first set only.
raising context/ CollapseContext/ RemoveContext something should help....looking at the requirement you dont need to opt for an UDF.
Regards,
Abhishek.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suman,
Please try the below without UDF. Please place Field1, Field 2 and Field 3 in a common context. 3 fields should be under same parent. You can take any parent which has 3 in the upper hierarchy.
Field 1 - mapWithDefault
Field 2 - mapWithDefault
Field 3 - mapWithDefault
Use <ifWithoutElse>. 1st input - Field1, 2nd input - Field3. THEN -> Field2. if you find target is not getting populated for Black Suppress, use <removeContext> and corresponding <splitByValue>. If you find Blue Suppress, let me know.
Hello,
Each and every time it is giving output to wrong records.
If the condition of the first record failed and second record is true then second record values is passing to first record
I should get for first record blank( because it failed the condition) , for second record it should get the corresponding value
Regards
Suman,
field1, field2 and filed 3 will occur equal no. of times?
raj.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes Raj...
Those all 3 fields come equal no. of occurrences always.
Ex:
<Field1>11</Field1>
<Field2>11</Field2>
<Field3>Result1</Field3>
<Field1>12</Field1>
<Field2>15</Field2>
<Field3>Result2</Field3>
<Field1>16</Field1>
<Field2>16</Field2>
<Field3>Result3</Field3>
In this case expected output is <Field3>Result1</Field3> and <Field3>Result3</Field3>
If that fied1 and field2 are matched i will have to populate field3 every time else do not populate in target segment at all
Regards
Hi,
Use this:
int a=var1.length;
int b= var2.length;
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
if(var2[j].equals(var1i )) ("i" is under square brackets)
{
result.addValue(var3[j]);
}
}
}
mapping:
Field1(xyz)----
Field2(ABC)--
Filed1(ABC)----
NOTE: Change the context of all the 3 input fields(set the context to its message type name).
Thanks
Amit
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
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.