Try OpenEdge Now
skip to main content
ABL Essentials
Using Basic ABL Constructs : Using program variables and data types : Placement of variable definitions
 

Placement of variable definitions

Where you place variables in your code is important. The AVM performs a single pass through the statements in a procedure to build the intermediary code that it uses to execute the procedure. Because a variable is a definitional element of a procedure and not a statement that is executed in sequence, it does not really matter where the variable definition appears. However, because of the one-pass nature of the ABL syntax analyzer, the definition has to appear before the variable is used in the procedure. By convention, it is usually best for you to define all your variables at the top of a procedure, to aid in readability and to make sure that they're all defined before they're used.
For the next change to the test procedure, you will put to work several of the concepts you've just learned about. Your code will display a special value for each Order record. This task involves defining a variable with an initial value, writing an IF-THEN construct with a check for the Unknown value (?), and then using one of the many built-in ABL functions to extract a value to display. The displayed value is the ShipDate month of an Order expressed as a three-character abbreviation, such as JAN or FEB.
To build up the list of possible values for the month, you need to define a CHARACTER variable to hold the list. Add the following variable definition to the top of your procedure:
DEFINE VARIABLE cMonthList AS CHARACTER NO-UNDO
  INITIAL "JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC".