Introduction

Language Structure

IB Statements

File System

Comet 32 Runtime

Index

COMMON statement

Syntax: COMMON variable-list
Discussion: The COMMON statement defines data variables to be used by more than one Internet Basic program. Common variables can be "overlayed" into the same partition as the current program, or passed to a program in another partition (e.g., a background partition).

All variables (other than Comet system variables) 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 COMMON statement.

The COMMON statement generally follows a related LENGTH statement. String variables defined in the variable-list must be preceded by a LENGTH statement which defines the length of the fields. Numeric variables do not necessarily require a LENGTH statement; those with no preceding 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: You must define common variables in the same order and with the same length in each program that shares the variables. Variable names can be different from program to program, although it is good practice to keep them consistent.

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 variable 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
COMMON NAME$, ADDRESS1$, ADDRESS2$, CRLIMIT
In the above example, three string variables and one numeric variable are defined as common data variables. The LENGTH statements preceding the COMMON statement determine the length and precision of the fields listed in the COMMON 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 & COMMON ZIPCODE$
This example shows how two statements may be combined 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 COMMON statement defines a common string variable called ZIPCODE$.