Using program variables and data types
- Last Updated: March 30, 2020
- 3 minute read
- OpenEdge
- Version 12.2
- 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.)
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
CHARACTERdata 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 forCHARACTERfields is 8 characters. The X symbol represents any printable character, and the 8 in parentheses effectively repeats that character, so that X(8) is the same as XXXXXXXX. The default value for aCHARACTERvariable 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/9999 as 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
DECIMALdata type supports a total of 50 digits of which up to 10 can be to the right of the decimal point. When you define aDECIMALvariable you can specify the number of positions to the right of the decimal point by adding the qualifierDECIMALS <n>to theDEFINE VARIABLEstatement. - ABL supports the automatic conversion of both
DATEs andDECIMALs 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 inDECIMALformats are converted to commas, and commas are converted to periods. In addition, the defaultDATEdisplay becomes DD/MM/YY or DD/MM/YYYY instead of MM/DD/YY or MM/DD/YYYY. - The
HANDLEdata 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
INTEGERvariable is 2G (slightly over a billion digits). - A
LOGICALvariable represents aYES/NOorTRUE/FALSEvalue. You can specify any pair of literals you wish for theTRUEandFALSEvalues that are displayed to the user for aLOGICALvariable, with theTRUEorYESvalue first. However, it is not advisable to useLOGICALs to represent data values that aren't 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 theTRUEvalue represents. - You will learn about the ABL Unknown value (
?) in Using the ABL Unknown value. The default display format forDATEthat has the Unknown value (?) is blank; for other data types it is a question mark.