| Discussion:
|
The LOCAL statement defines all data variables that will be used
exclusively by the current Internet Basic program (i.e., they will not be
shared with or "overlayed" to other Internet Basic programs.)
All variables (other than Comet ) used in the
I/O Format Division or Procedure Division of a program must be
declared as COMMON or LOCAL.
The variable-list includes Internet Basic variable names, each separated by
a comma or blank space. Any number of variables can be declared
with one LOCAL statement.
The LOCAL statement generally follows a related LENGTH
statement. String variables defined in the variable-list must be
preceded by a LENGTH statement defining the length of the fields.
Numeric variables do not necessarily require a LENGTH statement;
those with no preceding numeric LENGTH statement are assigned a
default length and precision of 8.2.
Array definitions must include the number of elements (or the
maximum number of indices for multi-dimensional arrays) as an
integer constant or symbolic constant enclosed in parentheses.
For example, ALPH$(26) defines a string array named ALPH$ with 26
elements, and VALUE(3,24) defines a numeric array named VALUE
with 3 columns and 24 rows. See Arrays for more information.
Note: LOCAL statements may be mixed with COMMON statements
without affecting the mapping of COMMON variables.
| Application notes:
|
- Defining some variables as COMMON and some as LOCAL allows you
to initialize selected variables with the CLEARCOMMON and
CLEARLOCAL statements. For more information, see the
CLEAR statement.
- Frequently, data variables definitions are used in more than
one source program. In these cases, the most practical way to
compile the same definitions into multiple programs is to
define them in "usefiles." Then, in each individual source
program, all you need to do is include the USE directive -- the
corresponding usefile definitions will automatically be
included in the resulting compiled program.
|
| Example 1:
|
LENGTH 25
LENGTH 9.2
LOCAL NAME$, ADDRESS1$, ADDRESS2$, CRLIMIT
In the above example, three string variables and one numeric
variable are defined as local data variables. The LENGTH
statements preceding the LOCAL statement determines the length
and precision of the fields listed in the LOCAL statement.
For example, LENGTH 25 defines the length of NAME$, ADDRESS1$,
and ADDRESS2$ (i.e., they will each store a maximum of 25
characters). The LENGTH 9.2 statement defines the length and
precision of the numeric variable CRLIMIT (i.e., it will store up
to nine digits, two of which will be to the right of the decimal
point).
|
| Example 2:
|
LENGTH 10 & LOCAL ZIPCODE$
This example shows how two statements may be written on a single
source program line. In this case, the LENGTH 10 statement
declares that the following string fields will store a maximum of
ten characters. The ampersand symbol (&) indicates that another
statement follows on the same line. The LOCAL statement defines a
local string variable called ZIPCODE$.
|
|