User Guide > Scripting > Variables > Scoping Variables
Was this helpful?
Scoping Variables
Scope Levels
Actian DataConnect supports declaring variables in the three scope levels of local, private, and public, as shown below.
Scope
Declaration Syntax
Scope description
Public
Public X
The data type can also be specified after “As”.
Public X As Object
The variable is visible to all scripts in the process or transformation, and all sub-processes in the process, and technically in all parent processes. In other words, at runtime, any script module has access to the variable.
This scope is denoted by declaring the variable PUBLIC.
Private
Private X
Global X
The data type can also be specified after “As”.
Private X As DJImport
The variable is visible to all scripts in the process or transformation, but is not visible outside the executing process or transformation.
This scope is denoted by declaring the variable PRIVATE or GLOBAL.
Note:  Originally there was only GLOBAL scope, we later added PUBLIC and so renamed GLOBAL to PRIVATE (while still accepting GLOBAL to mean PRIVATE).
Module
Dim num as integer
Function A
...
End Function
Function B
...
End Function
Variables with MODULE scope are available anywhere within the single script expression. For example, in a target field mapping expression, if you declare a variable, it is visible within that mapping expression, but not to any other mapping expressions.
Local (default)
Function Y
  Dim X
End Function
Variables with LOCAL scope are visible only within the function they are declared in.
You can use the DIM keyword to declare a variable within the function to give it a LOCAL scope.
Note:  If Option Implicit is on (in other words, Option Explicit is off) and you simply reference a variable, then it is scoped as if the previous statement was a “DIM variable”, in other words LOCAL if used within a function definition, otherwise MODULE scope.
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
Last modified date: 12/03/2024