cancel
Showing results for 
Search instead for 
Did you mean: 

User Defined Node Function

Former Member
0 Kudos

Hi all,

How can I pass in the actual "node" as a parameter to a user defined function? Such as passing in an IDOC segment tag <MATNR> as the parameter to see if it exists in the inbound idoc structure? Is this possible and how can it be done? Thank you for any help.

Accepted Solutions (1)

Accepted Solutions (1)

STALANKI
Active Contributor
0 Kudos

Jui,

Exists checks wether the tag is present in the incoming XML.But i guess the limitation is when the field is 0..unbounded it gives unexpected results...!Michal is absolutely right to use UDF instead of exists..!

Answers (2)

Answers (2)

prasad_ulagappan2
Contributor
0 Kudos

Hi Jui,

This can be done. Here it goes...

Create a UDF with cache as "Context". If you want to check for more nodes, include it as b,c,d... parameters in the UDF. (Default is "a"). And the code looks like the following.

Here I have used it for checking 3 nodes. The logic behind the code is that if all the 3 nodes exist, then it will concatenate all the three fields and produce the result node, if any one of them doesnt exist, then it will concatenate only the remaining fields.

try{
if(a.length != 0 && b.length != 0 && c.length != 0)
result.addValue (a[0] + b[0] + +c[0]);
else {
if(a.length == 0 && b.length != 0 && c.length != 0)
result.addValue( b[0] + c[0]);
if(a.length != 0 && b.length == 0 && c.length != 0)
result.addValue(a[0] + c[0]);
if(a.length != 0 && b.length != 0 && c.length == 0)
result.addValue(a[0] + b[0]);
}
}catch (ArrayIndexOutOfBoundsException e)
{
result.addSuppress();
}

Regards,

Prasad U

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

matnr is not a node but a field

so you can pass your field to the UDF and check

if there's any value inside?

or use the standard <b>exists</b> function

you can use the exist function with nodes too

you can also use this exists function (NODE functions)

to check if the node,fields exist and

return only the result to your UDF if you need

to do some more complex logic

Regards,

michal

-


<a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions"><b>XI / PI FAQ - Frequently Asked Questions</b></a>

Former Member
0 Kudos

Sorry I wasn't being clear with my wording. I know I can check whether a field is there with the exists function, or check if the field contains a value.. but what I want to know is exactly how I can pass the actual tag to a UDF to check if it is there? Basically how does the exists function work? I would like to know this because I want to write a more sophisticated function that is like exists but does a little more. Thank you.

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

if you add node to your UDF

and if you remove contexts you can check:

equals("") to see if the node exists

or equals(ResultList.CC) to see contex changes

Regards,

michal

Former Member
0 Kudos

Hi,

You could use a String array, (String[] a ) in the UDF signature, which will accept the field as input. (In case there are multiple occurences of the field).

Or you could use a String object (String a)to accept the value of this field.

In your UDF, you could check if it exists using,

if(a != null) {...}

Regards,

Smitha.