Program Structure
Each program written in CTL must contain the following parts:
ImportStatements VariableDeclarations FunctionDeclarations Statements Mappings
All of them may be interspersed; however, there are some principles that are valid for them:
If an import statement is defined, it must be situated at the beginning of the code.
Variables and functions must be declared before use.
Declarations of variables and functions, statements and mappings may also be mutually interspersed.
Important | |
---|---|
In CTL2, variables and functions may be declared in any place of the transformation code and may be preceded by other code. However, remember that each variable and function must always be declared before it is used. This is one of the differences between the two versions of CloverDX Transformation Language. |
Example 65.1. Example of CTL2 syntax (Rollup)
//#CTL2 string[] customers; integer Length; function void initGroup(VoidMetadata groupAccumulator) { } function boolean updateGroup(VoidMetadata groupAccumulator) { customers = split($in.0.customers," - "); Length = length(customers); return true; } function boolean finishGroup(VoidMetadata groupAccumulator) { return true; } function integer updateTransform(integer counter, VoidMetadata groupAccumulator) { if (counter >= Length) { clear(customers); return SKIP; } $out.0.customers = customers[counter]; $out.0.EmployeeID = $in.0.EmployeeID; return ALL; } function integer transform(integer counter, VoidMetadata groupAccumulator) { return ALL; }
Note the //#CTL2
header.
You can enable the CTL compiled mode by changing the header to //#CTL2:COMPILE
.
For more information, see Compiled mode.