Types of SAP PI UDF

There are 3 types of SAP PI UDF that you write in Graphical Mapping:

  • Simple UDF:
    • Single Values.
  • Advanced UDF:
    • All Values of a Context.
    • All Values of Queue.

User Defined Function (UDF) is a functionality of graphical mapping using which you can write simple java functions that can be used in mapping.

You can write Java Functions inside the UDF that accepts the input data and you write the output from the UDF.

types of sap pi udf

Single Value:

Single Value UDF are used when you want to pass input parameters and write some output from the UDF.

It is called as Single Values because you can pass only One field of the XML but cannot pass the entire payload.

You can pass multiple single values but you cannot pass segment of elements.

Simple UDF

When you define the Single Value Function observe the input parameters type.

single value function

Function Name: SimpleUDF
Input Parameter: String, String
Output Parameter: String

There are two input parameters of type String and output of function is type String.

You will also get Container instance using which you can get access trace, dynamic configuration and many other useful features.

Use case of Simple Values:

  • Change One Value.
  • Append Two values.
  • Search a value in the String.

All Values of a Context:

You can define UDF with All values of Context change to get values only from One Node.

This type of function will get all the values from that node and ignore next node values.

advanced-udf-function-context-1

Most important things you need to note is the result object of ResultList which is used to write the output to this object directly.

This how the Advanced UDF Function will look like:

advanced-udf-function-context-2

Input Type: String Array
Output Type: void (cannot return anything)
Result Parameter is used to write the output.

Lets Write a Advanced UDF with all Value in Content with the below code:

String output = “”;
for(int i = 0; i < input1.length;i++){
output = output + input1[i];
}
result.addValue(output);

advanced-udf-function-context-3

Mapping:

advanced-udf-function-context-4

Test Tab:

In the UDF, we read all the values of the ID and capture it in the output.

Still we see only first context value and it is unable to read the next context value ‘222’.

advanced-udf-function-context-5

All Values of Queue:

Lets create another UDF – Advanced_Queue_UDF

advanced-udf-function-queue-1

UDF Code is same:

As we are reading everything from the string array we should able to read the context change and also the next context values.

advanced-udf-function-queue-2

Map the UDF to the ID field:

advanced-udf-function-queue-3

Test Tab:

advanced-udf-function-queue-4

You can clearly see the difference between:

  • QUEUE ALL VALUE
  • CONTENT ALL VALUE

Queue All Value pass the entire queue to the User Defined Function of Type of All Values of Queue.

Context All Value pass just the context values to the User Define Function of Type of All Value of Content.

Srini
About the author

Srini - is an IT Architect who enjoys sharing knowledge on Computer Programming and Digital Marketing. Take a look at the Courses and Books.

Leave a Comment