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 DEFINE instruction.
  • After definition, variables get default values according 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 PRIVATE or PUBLIC.
  • You can define structured variables with records, and with arrays.
  • Default values (or NULL) can be assigned with the INITIALIZE instruction.
  • Direct value assignment is done with the LET instruction.
  • Database validation rules can be applied with the VALIDATE instruction.
  • Variables can be used as SQL parameters or fetch buffers in SQL statements.
  • Interactive instructions use program variables as model to hold the data.
  • Variables can be defined with attributes by using the ATTRIBUTES() clause.