User Defined Functions (UDF) are functions defined by a programmer, which can be used in SAP PI graphical mappings. UDFs are defined in Java programming language and allow running any custom code on XML field mapping stage, significantly extending possibilities of message field and value mapping.
UDFs are represented by one block in graphical mappings. They can be utulised to simplify implementation of logic, that requires using multiple standard mapping blocks:
UDF can be created by clicking the icon in lower-left corner of graphical mapping editor window:
In the simplest caase it is enough to provide some basic data – function’s name and title, and its input arguments. Arguments’ value can be assigned in the same way as for standard mapping blocks – using arrows on function’s input and output:
The next step is implementation of function in Java programming language. Input and output are handled in the same fashion as other Java functions or methods – through arguments and return statement. The below screen shows a UDF function, that works in the same way that the graphical mapping above.
Configuration values can be assigned as UDF parameters. They will be passed to the function as arguments, too, but their values are defined in graphical mapping editor.
After saving the function, it can be used in graphical mapping, connecting inputs and output. Similarly to standard mapping blocks, after running a test case, a queue of arguments and returned values can be viewed under Display Queue:
In the above example, UDF has been utilised to simplify value mapping implementation. Depending on needs, a programmer can use a variety of Java language features to implement more complex mappings, than standard mapping blocks allow.