Use program variables and data types
- Last Updated: March 19, 2024
- 3 minute read
- OpenEdge
- Version 12.8
- Documentation
Like most programming languages, ABL lets you define program variables for use within a procedure. Here is the basic syntax:
Syntax
|
In this syntax, varname is the name of the variable, which must conform to the same rules as other names in ABL. (See Variable naming conventions for details.)
You may also use the newer
For more information, see Learn about the VAR statement.
VAR statement to define a
variable:
|
ABL supports a range of data types. The following table lists the basic ones. There are some other special data types available for more advanced programming, but these are enough to get you started.
| Data type name | Default display format | Default initial value |
|---|---|---|
| CHARACTER | X(8) |
"" (the empty string) |
| DATE | 99/99/99 |
? (the Unknown value, which displays
as blank for dates) |
| DECIMAL | ->>,>>9.99 |
0 |
| HANDLE | >>>>>>9 |
? (the Unknown value) |
| INTEGER | ->,>>>,>>9 |
0 |
| LOGICAL | yes/no |
no |
Here are a few notes on ABL data types:
- All CHARACTER data in ABL variables, and in database fields in an OpenEdge
database, is stored as variable length strings. You do not need to define the length of a
variable, only its display format, which indicates how many characters (at most) are
displayed to the user. The default display length for CHARACTER fields is 8 characters.
The
Xsymbol represents any printable character, and the 8 in parentheses effectively repeats that character, so thatX(8)is the same asXXXXXXXX. The default value for a CHARACTER variable is the empty string. - You can display dates in a variety of ways, including two- or four-digit
years. To get a four-digit year, specify
99/99/9999as your format. Note that changing the display format for a date does not change how it is stored in the database. Dates are stored in an internal format that can be converted to any of the display formats available to you. - The DECIMAL data type supports a total of 50 digits of which up to 10 can
be to the right of the decimal point. When you define a DECIMAL variable you can specify
the number of positions to the right of the decimal point by adding the qualifier
DECIMALS nto theDEFINE VARIABLEstatement. - ABL supports the automatic conversion of both DATEs and DECIMALs to the
formats generally used in Europe and other parts of the world outside the US. If you use
the European (
–E) startup option, then all period or decimal characters in DECIMAL formats are converted to commas, and commas are converted to periods. In addition, the default DATE display becomesDD/MM/YYorDD/MM/YYYYinstead ofMM/DD/YYorMM/DD/YYYY. - The HANDLE data type is used to store a pointer to a structure that represents a running ABL procedure or an object in a procedure such as a field or button.
- The maximum size of an INTEGER variable is 2G (slightly over a billion digits).
- A LOGICAL variable represents a YES/NO or TRUE/FALSE value. You can specify any pair of literals you wish for the TRUE and FALSE values that are displayed to the user for a LOGICAL variable, with the TRUE or YES value first. However, it is not advisable to use LOGICALs to represent data values that are not really logical by nature, but which simply happen to have two valid values, such as Male/Female, because it might be unclear which of those the TRUE value represents.
- You learn about the ABL Unknown value (
?) in Use the ABL Unknown value. The default display format for DATE that has the Unknown value (?) is blank; for other data types it is a question mark.