User Guide > Scripting > Script Objects > Object Variables
Was this helpful?
Object Variables
You can use object variables in expressions. An ordinary variable can be thought of as a name for a location in the computer's memory that holds data. An object variable is a name for a location in the computer's memory that holds a reference (or pointer) to an object.
To use object variables in the Map window, declare and instantiate an object (as in the BeforeTransformation event). Then, create a reference to the object.
Use the New keyword with internal objects (DJIMPORT, DJEXPORT, DJFIELD, DJRECORD).
Set MyObject = New DJIMPORT "Access 97"
Note:  Connector name, in this case "Access 97", must be exactly the same as it is listed in the Map window. For example, typing "Access" does not work.
Use the object, then release it by using the AfterTransformation event:
Set MyObject = Nothing
Note:  For object variables only (not for ordinary scalar variables, nor arrays), clear the reference to the object using the Set and Nothing keywords.
See Also
Declaring Object Variables
Assigning a value to an object variable must be done using the Set operator. Assignment is the only action you can take with an object variable alone. If you want to do something else with the object, use one of the object properties for the object type.
The examples below show several scenarios for declaring object variables.
Example 1
'This example declares the variable F as a DJField type of transformation-wide object variable.
Private F As DJField
Example 2
'This example declares the variable F as a DJField type of local object variable.
Dim F As DJField
Example 3
'This example assigns the object variable F to be a pointer to the default field (generally the first field in a source file).
Set F = FieldAt("/SOURCE/R1/MyField")
Internal Object Variables for Mapping
The internal object variables available in the Map window include: djimport, djexport, djrecord, djfield, err, and sys.
You must declare object variables before you set them. However, you cannot set the err and sys variables.
For the object properties you can use with these variables, see Script Objects.
Name
Description
Default Property
DJImport
Source type or source connector. This must be set to one of the entries on the source connlist, exactly (case sensitive) as shown in the Map window.
Name
DJExport
Target type or target connector. This must be set to one of the entries on the target connlist, exactly (case sensitive) as shown in the Map window.
Name
DJRecord
Record type. This must be set to one of the record type names that you have defined within the Map window.
Name
DJRowset
Container for storing collections of record instances. Using this object is more convenient for storing record images than arrays.
None
DJField
Field name. This must be set to a specific field in the source or target table.
Value
Err
Most recent error encountered in the expression process.
Error code from last error
Sys
System object. You can use the System keyword to make global changes. See Retrieving and Setting LogFile and LogMask Properties.
None
Example
'Place this expression in an Execute action at the BeforeTransformation event.
Private x As DJField
x = FieldAt("/SOURCE/R1/MyField")
x.Value
'This returns the data in the default (usually first) source field.
Note:  Mapping does not support object variable arrays.
Err Object Variable
The Err object variable contains a reference to a system object used to provide information on EZscript exceptions.
Tip...  The Err object variable only exists for EZscript. Use the Project Object to retrieve the error count and return codes for other process steps.
The Err object properties are accessed in the same way as with Visual Basic. Err.Number is the error number; Err.Description is the error description, and so on. These properties are read-only.
Property
Type
Access
Description
Number
Integer
RO
Error code from the last error (default property).
Description
String
RO
String describing last error.
Source
String
RO
Name of integration language source code module where error occurred.
Line
Integer
RO
Line number in source code where the error occurred.
StackTrace
String
RO
String with a stack trace showing the stack frames from when the error occurred.
Many run-time errors are trappable using run-time error trapping statements, such as On Error GoTo Statement.
To find out what error was trapped, use the Err object. Err object properties are reset every time a run-time error trapping statement is executed.
Example of Using the Err Object
When the EZscript code below is executed, the following error message appears:
Error 114 DivideByZero(StackTrace.ezscript:2)
StackTrace.ezscript:
'Define a function that returns a Divide By Zero exception:
Function DivideByZero(a)
  Return a / 0
End Function

'Define a function to call DivideByZero, trap the exception, and print a stack trace:
Function test()
  On Error GoTo err_Test
  Return DivideByZero(10)
  err_Test:
    LogMessage("Info","Error & Err.Number)
  LogMessage("Info",Err.StackTrace)
End Function

'Execute the test function:
test()
Last modified date: 02/01/2024