Altova MapForce 2024 Professional Edition

User-Defined Functions

Home Prev Top Next

User-Defined Functions (UDFs for short) are custom functions that are defined once and can be reused multiple times within the same mapping or across multiple mappings. UDFs are like mini-mappings themselves: They typically consist of one or more input parameters, some intermediary components to process data, and an output to return data to the caller. The caller is the main mapping or another UDF.


Advantages of UDFs

UDFs have the following advantages:


UDFs are reusable within one mapping or across multiple mappings.

UDFs can make your mapping easier to read: For example, you can package parts of the mapping into smaller components and abstract away the implementation details. The diagram below illustrates this principle.


UDFs are flexible functions that enable you to process strings, numbers, dates, and other data in a custom way that extends the built-in MapForce functions. For example, you might want to concatenate or split text in a particular way, perform some advanced calculations, manipulate dates and times, and so on.

Another common use of UDFs is to look up a field in an XML file, database or some other data format supported by your MapForce edition and present this data in a convenient way. For details, see Look-up Implementation.

UDFs can be called recursively (i.e., the UDF calls itself). This requires that the UDF be defined as a regular (not inline) function. Recursive UDFs can fulfill various advanced mapping requirements, such as iterating over data structures having a depth of N children, where N is not known in advance.



Below is an example of a simple UDF that splits a string into two separate strings. This UDF is part of a larger mapping called MapForceExamples\ContactsFromPO.mfd. The UDF takes the name as a parameter (e.g., Helen Smith), applies the built-in functions substring-before and substring-after, and then returns two values: Helen and Smith.



In this section

This section explains how to work with UDFs and is organized into the following topics:


UDF Basics

UDF Parameters

Recursive UDFs

Look-up Implementation


© 2018-2024 Altova GmbH