IMan (VB)Script Language Reference¶
IMan uses our own variant of the Scripting language. The (VB) Scripting language is used throughout IMan: Map, Filter, Aggregate transforms; Script Task; evaluated expressions such as File Names and URLs.
The main characteristics of the IMan (VB) Script Language:
- Based on VBScript
- It is dynamically typed - There are no explicit type (String, Integer, Boolean) declarations.
- Most of the constructs and features of VBScript are valid an usable in IMan.
- All the inbuilt VBScript Functions such as (Mid, Replace, Instr) can be invoked. These are augmented by numerous IMan specific functions such as Lookup, Sum, Count.
- Field values from IMan can be referered with %FieldName syntax.
- Expressions do not have function opening or function close statements.
- There is no explicit expression result declaration - last line of the expression is the result.
Components of the (VB)Script Language¶
The IMan (VB) Script language is a full-featured language consisting of features in a language: variables, control flow and looping.
- Field and Record Evaluation Expressions
- (On this page) What are expressions.
- Field References
- (On this page) How to reference IMan data from in an expression.
- Syntax
- General Script syntax such as reserved names and comments.
- Functions
- How to call (and define your own) functions such as Mid, Lookup, etc.
- Variables
- How to declare variables to hold temporary values in expressions or functions.
- Operators
- How to use the different operators such as +, /, Mod, And, Or, &.
- Decisions
- How to use If...Then...Else type statements.
- Loops
- How to perform loops on collections or arrays of data.
- Looping should not be confused with the general Data Processing Pattern.
- Arrays
- How to declare and resize Arrays / collections of data.
- Error Handling
- A short discussion on error handling.
What is a Expression?¶
An expression is a script statement. It returns a value.
This may be a small, single line script, or a multi-line script.
Field and Record Evaluation Expressions¶
Expressions can be found in many places in IMan and classified into three broad categories.
- Field expression
- Individual field level and are used to set field values - found in Map and Aggregate transforms.
- Can be written over multiple lines and support local variables.
- Record evaluation expression
- Record evaluation expressions apply to an entire record, with all its field and are used for conditional evaluation such as the Filter and Aggregate transforms.
- Can be written over multiple lines and support local variables.
- Inline Expressions
- In-line expressions are limited to a single line which must evaluate to a result. These expressions are used primarily in transform set-up fields to dynamically generate a specific entry, such as a file name in a Writer transform.
- Are a single line i.e. are purely functional - they do not support any variables.
Important
The last line of the formula is used as the result.
Example
Multi-line Function with a Valid Return Value
Example
Multi-line Function with an Invalid Return Value - the last line is variable declaration.
Example
The return value is supposed to be NetValue, but the formula actually returns a Boolean comparison of the NetValue variable and the difference of the GrossValue and TaxTotal fields.
The correct formula should be:
Which could be further simplified to a single one line expression:
Field References¶
Field references allow data in the IMan dataset to be referenced and manipulated.
Field references have the following syntax:
or
- %
- Identifies the following statement as a field reference.
- FieldName
- The name of the field being referenced.
If there are spaces or special characters within the field name/transaction Id, enclose the field references in square brackets.
Example
The following example uses two field references GrossTotal and TaxTotal - each of these refer to fields in the dataset.
If the GrossTotal and TaxTotal fields had 1200 and 400 respectively the resulting expression would be -800.
The same example can be shown with the square bracket around the field reference syntax.