VAR statement
- Last Updated: February 11, 2026
- 4 minute read
- OpenEdge
- Version 13.0
- Documentation
Defines a variable. The VAR
statement is a short-hand notation for the DEFINE VARIABLE statement. Variables defined with the VAR statement are NO-UNDO, meaning
that the value of the variable will not be restored if the variable changed during a
transaction and the transaction is undone. If you wish to have the option to restore
the variable to its prior value, use the DEFINE
VARIABLE statement instead.
Syntax
|
- access-mode
- Specifies an access mode (
PRIVATE,PACKAGE-PRIVATE,PROTECTED,PACKAGE-PROTECTED, orPUBLIC) for the user-defined class variable. For more information, see Access modes in Object-oriented ABL Developer Guided Journey. - STATIC
- Indicates that the user-defined class variable is scoped
to the ABL session where it is referenced. ABL creates one copy of the
specified class static variable on first reference to the class type, and
ABL creates only one such copy for any number of instances of the class that
you create. You can reference an accessible static variable data member in
any piece of code
Without the
STATICoption, the user-defined class variable is scoped to a single instance of the class where it is defined. ABL creates one copy of the specified instance variable for each such class instance that you create. You can reference any public instance variable in any procedure, or in any instance or static method defined inside or outside of the class where the instance variable is defined. Any static method can reference the public instance variable only using an object reference to a class instance that defines the variable as a data member. If the referencing static method is defined in the same class as the public instance variable, the class must instantiate itself in order to have access to an instance reference. - SERIALIZABLE | NON-SERIALIZABLE
- Indicates whether the user-defined class variable will
participate in serialization.
SERIALIZABLEandNON-SERIALIZABLEoptions can only be used with instance (notSTATIC) variables. For more information, see Serialization and deserialization in Develop Object-oriented ABL Applications. - type
- Specifies a built-in data type for the variable you are
defining. Type can be one of the
following: CHAR, CHARACTER, COM-HANDLE, DATE, DATETIME, DATETIME-TZ,
DECIMAL, HANDLE, INT, INTEGER, INT64, LOGICAL, LONGCHAR, MEMPTR, RAW, RECID,
or ROWID. Type cannot be
abbreviated.Note: CHAR is a synonym for CHARACTER and INT is a synonym for INTEGER.
For more information on ABL data types, see Data types.
- [CLASS] classname
- Indicates that the variable is an object of type classname. The
CLASSkeyword is optional. However, if the specified class or interface type name conflicts with an abbreviation for a built-in primitive type name, such as INT for INTEGER, you must specify theCLASSkeyword.For more information on object references, see the Class-based object reference entry.
- [size]
- Indicates that the variable is an array. size is optional and specifies the number of
elements in the array. If size is
specified, it must be an integer constant. If size is not specified (
[]), then the variable is considered an indeterminate array. For more information about arrays, see Work with one-dimensional arrays in Basic ABL. - variable
- Specifies the name of the variable. Variable names must begin with a letter, but subsequent characters can include letters, numeric digits, periods(.), hyphens(-), and underscores(_). Variable names are case-insensitive.
- expression
- An Expression
which evaluates to a data type that is consistent with the data type of the
defined variable.Note: Using Scientific notation format is allowed for DECIMAL, INTEGER, and INT64 types.
Examples
The following example code shows variable declarations using
VAR.
|
Notes
VARmay only be used at the beginning of an ABL routine, before any executable statements in the block.If in a procedure, theVARstatement must follow these statements:USING...BLOCK-LEVEL ON ERROR UNDO, THROW.ROUTINE-LEVEL ON ERROR UNDO, THROW.
If in a class, theVARstatement:- Must come after the
CLASSstatement. - Can be in any order within the class, like other class members.
- Must be at the top of the block within a method or property body.
VARdoes not allow abbreviated data types. For example, when specifying a decimal variable, you cannot writeVAR DEC. You must writeVAR DECIMAL. In Release 12.3, CHAR and INT are actual keywords and not abbreviations. CHAR is a synonym for CHARACTER and INT is a synonym for INTEGER. Therefore you can writeVAR CHARorVAR INT.- Other options allowed with the
DEFINE VARIABLEstatement, such asFORMATorLABEL, cannot be used withVAR. If you need those other options, use theDEFINE VARIABLEstatement instead. - Uninitialized elements in a
determinate array object variable are set to the Unknown (
?) value, unlike scalar array variables where uninitialized elements are set to the last initialized value, if any.
See also
DEFINE VARIABLE statement, Data types, EXTENT statement, NEW function (classes)