Understanding variables
This is an introduction to variables.
A variable is a program element that can hold volatile data. The following list summarizes variables usage:
- Variables are declared in programs with the
DEFINEinstruction. - In the definition of a variable, you can specify a value as initializer, for simple and structured types.
- After a definition without initializer, variables get default values specific to their type.
- The scope of a variable can be global, local to a module, or local to a function.
- When defined at the module level, a variable can be declare it as
PRIVATEorPUBLIC. - You can define structured variables with records, and with arrays.
- Default values (or
NULL) can be assigned with theINITIALIZEinstruction. - Direct value assignment is done with the
LETinstruction. - Database validation rules can be applied with the
VALIDATEinstruction. - Variables can be used as SQL parameters or fetch buffers in SQL statements.
- Interactive instructions (dialogs) use program variables as model to hold the data.
- Variables can be defined with attributes by using the
ATTRIBUTES()clause.