ABL lets you define program variables for use within an application. The variables must be defined with a specific data type. After the variables are defined you can assign values to them.

Define a variable

Variable definitions are typically placed at the beginning of your code. In ABL you do this using the DEFINE VARIABLE statement. The basic simplified syntax is:

DEFINE VARIABLE varname AS datatype
  [ INITIAL { value }
  [ EXTENT [ n ]
  [ NO-UNDO ].
varname
Specifies the name of the variable.
datatype
Specifies the data type of the variable, for example, CHARACTER, INTEGER, DECIMAL, DATE, LOGICAL. See the table below for a list of supported data types.
INITIAL value
Optionally specifies an initial value for the variable. If specified it must be a constant. See the table below for a list of default initial values for each data type.
EXTENT n
Optionally specifies that the variable is an array of size n. The size must be an integer. Once defined you can then reference the individual array elements in your code by enclosing the array subscript in square brackets, as in myVar[2] = 5.
NO-UNDO
Specifies that the variable does not require transaction support. The best practice is to always use NO-UNDO for variables unless explicitly required, to prevent unnecessary overhead.

ABL supports a range of data types and each data type has a default initial value which can be overridden. The ABL data types are listed in the following table.

Table 1. Data types
Data type name Default initial value
CHARACTER "" (The empty string)
CLASS object-type-name Unknown value (?)
DATE Unknown value (?)
DATETIME Unknown value (?)
DATETIME-TZ Unknown value (?)
DECIMAL 0
HANDLE Unknown value (?)
INTEGER 0
INT64 0
LOGICAL no
LONGCHAR Unknown value (?)
MEMPTR Unknown value (?)
RAW A zero-length sequence of bytes
ROWID Unknown value (?)

Assign a value to a variable

ABL assigns values to variables using the assignment operator (=). In the following example the variable, name, is set to the string, NewCustomer.

/* Set a local string variable to "NewCustomer" */

DEFINE VARIABLE name AS CHARACTER NO-UNDO.

name = "NewCustomer".

ABL Unknown value

For certain data types, when a value has not yet been assigned to the data element, ABL associates the Unknown value with the data element. In ABL you represent the Unknown value with a question mark (?). Note that you do not put quotation marks around the question mark; it acts as a special symbol on its own. The Unknown value (?) is not equal to any defined value. In ABL you write a statement that looks as though you are comparing a value to a question mark, such as: IF ShipDate = ?, but in fact the statement is asking if ShipDate has the Unknown value, which means it has no particular value at all. The Unknown value is like the NULL value in SQL, and the expression IF ShipDate = ? is like the SQL expression IF ShipDate IS NULL.

See also

DEFINE VARIABLE statement

Other variable qualifiers

Data types

Using program variables and data types

Assigning a value to a variable

Using the ABL Unknown value