cancel
Showing results for 
Search instead for 
Did you mean: 

Need help to create an UDF

0 Kudos

Hi experts,

Please help me in creating an UDF. Below is the requirement.

Source

 

---Orders...................1-n

-----Header.................1-1

-------PONo.................1-1

-----Item...................1-n

-------Charecterestics......1-n

-----------ObjectNo

-----------ObjectType

-----------Groupcode

-----------CharDesc

-----------CharVal

-----------NumVal

                    :

                    :

                    etc

Target field will occur for every Orders.

Requirement is for all "Charecterestics"(will come 'n' times) check if "ObjectNo" matches with "PONo" (1 occurrence for each "Orders" but n number of "Orders" can come), if matches then check if value present in "CharVal" take the value else take value from "NumVal". If "ObjectNo" does not matches with "PONo" ignore that "Charecterestics".

Either of CharVal or NumVal will have value.

I tried with graphical mapping and it worked but the problem is, there are similar logic with different fields which are huge in number and for that I need a UDF which can be used everywhere.

Please help me out.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

Try this UDF:

Execution type: all values of a context

Input: var1, var2, var3, var4

for(int i=0;i<var2.length;i++)

{

if(var2[i].equals(var1[0]))

{

if(var3[i].length()>0)

result.addValue(var3[i]);

else

result.addValue(var4[i]);

}

}

Mapping:

PO_No --------\

Object_No**---------------------UDF------SplitByValue(Each value)---Target

CharVal**-------------/

NumVal**----------------/

** ->change the context of this field and set it to orders

Thanks

Amit Srivastava

0 Kudos

Hi Amit,

Thanks for your prompt reply. I tried with the logic it worked a little. But for certain cases it is not working.

There might be scenarios where if CharVal is present then NumVal might not come(I mean the tag itself might not come as the occurrence is 0-1). In those case it is failing.

For example, I have tested with one Order and 3 characteristics. For the first one the Object_No is not matching and there is no tag for NumVal, for the 2nd Char the object number is matching but tag CharVal is absent. Ideally the program will pick the value from NumVal. But it is not able to pick the value from NumVal.

Let me know if I am not able to make you understand the scenario.

Former Member
0 Kudos

If the tag does not come, use Map With Default (some value) before you pass that value to the UDF. Then in the UDF code, handle that.

Or I assume to you can check for a null in the UDF, but Java is not my strong point (and I am on the PI, go figure).

Former Member
0 Kudos

Hello,

>>There might be scenarios where if CharVal is present then NumVal might not come

This information was missing in ur previous post....so, to put things in perspective always try to post input and expected output structure.

Anyway, try below mapping:

Note - This time only change the context of Object_No field and set it to "Orders"

Thanks

Amit Srivastava

0 Kudos

Sorry Amit for not providing with the correct requirement at the first go.

Thanks for your help. It worked.

Answers (2)

Answers (2)

ambrish_mishra
Active Contributor
0 Kudos

Hi,

Unless you share the target structure and field level logic, it will be difficult to imagine a solution.

Ambrish

gagandeep_batra
Active Contributor
0 Kudos

Hi Subhra

Can you paste ur required target structure also.

Regards

Gagan