Sub Functions make it possible to create and re-use your own functions. This has a number of key advantages;
Transforms can quickly become crowded with implementation detail making them difficult to read and maintain. By pushing functionality into sub functions that perform a specific task, you can keep the transforms easy to understand and simpler to maintain and edit.
Sub functions can be used to build up a library of your own functions that can be incorporated into a number of other transforms and sub functions. Sub functions make reuse possible while keeping a project maintainable and modular enough for teams to work collaboratively on.
Creating a Sub Function
A Sub Function can be created by selecting one or more related Components and clicking on the "Create Function" () command.
The components selected above make the first letter of a string uppercase and the rest lower case.
A Sub Function is created from them by selecting the components (drag select, or click holding down the ctrl key), the clicking the "Create Function" () command on the toolbar or context menu.
Once a sub function has been created the new transform is much easier to understand, and our new function is simple enough to be understandable and maintainable.
Notice the inputs to the sub function are shown in green, and the outputs in red.
|The inputs and outputs can be primitive types (as in this example, or they can be complex types like database tables or XML schema elements).|
Once a Sub Function has been defined it can be re-used as many times as needed from any Transform or Sub Function in the project.
Sub functions can not be recursive, i.e they can not call themselves, either directly or via a nested sub function .
So the following is valid A calls B calls C, but now C can NOT call A or B.
Once a Sub Function has been created it can be seen in the Component Palette and used by dragging it onto the transform.