User Guide : Scripting : Variables : Scoping Variables
Share this page             
Scoping Variables
Scope Levels
DataConnect supports declaring variables in the three scope levels of local, private, and public, as shown below.
Scope Level
How Declared
Extent of Existence
Local (default)
Use Dim inside a function or at the beginning of a module.
Function Y
  Dim X
End Function
Dim X
Function A
End Function
Function B
End Function
Available within a function or at the beginning of a module.
The data type can also be specified after "as".
Private X
Global X
Private X as DJImport
Note:  Global declaration is still supported for backward-compatibility, but Private is the preferred syntax.
Available to all expressions within a single process or map.
Be cautious when using any function that declares a private variable within a process. If you call that function from a Process step, the function fails since it is not able to access the private variable.
The data type can also be specified after "as".
Public X
Public X as Object
Available to all expressions or maps within a process, except maps called from Process steps. In that case, the Public variable must also be declared within the Process steps.
Local Scope Notes
A local variable is local to the expression in which it is defined. So, if you create a variable using the Dim statement in one step of a process, its contents are not available to other process steps. If you want to create a local variable to use in multiple expressions or steps within a process, you must create multiple local variables, each with the same name. Each of the expressions or steps needs its own Dim statement. A better method for sharing the same variable among multiple steps is to declare the variable as either Private or Public.
Public Scope Notes
Public variables are available within a process and to all transformations and steps within that process. For example, values can be passed from one transformation to another or from a Decision step to a Script step. Keep the following in mind when working with public variables:
Public variables are not available to transformations within Process steps unless they are also declared within the Process steps.
To execute a transformation independently from the Map window, from the command line, or if you want to be able to test that step only, declare the same public variable in one of the modules inside the Map window.
To test a Transformation step that contains an undeclared but referenced Public variable, select the step that contains the variable declaration along with the Transformation step. Then test both steps together. This allows the transformation to execute properly.
See Also
Guidelines for Naming Variables
Variant Data Type
Array Variables
Clearing Variables and Array Elements
Option Evaluate Automatic Statement
Option Implicit Statement