COM [/store/] var [,var2][. . .] COMMON [/store/] var [,var2][. . .]
|store||Optional — A named storage area for the listed variables. If specified, this name is enclosed with slashes (/).|
|var||A variable or a comma-separated list of multiple variables.|
The COMMON statement allows you to specify list of local variables that are placed in a common storage area available to external subroutines. You can specify one variable or a comma-separated list of variables. These variables do not have to be defined to be listed as common. A variable placed in a common storage area may contain a literal value or an object reference.
You can use store to specify a named common storage area, or omit this argument and store the listed variables in the unnamed common storage area. A store name can be of any length, but it suggested that it be unique within its first 27 characters.
You specify a COMMON statement in both the calling program and each called subroutine that uses the variables. The corresponding variables in an external subroutine do not have to have the same names; they correspond by being in the same sequence. Thus the first variable in the main program's COMMON statement corresponds with the first variable in the external subroutine's COMMON statement, the second with the second, and so forth.
Specifying an array in a COMMON statement dimensions that array; it cannot be subsequently dimensioned using a DIM statement. Attempting to do so results in a compile error.
Arrays dimensioned in COMMON areas in one program do not need to be dimensioned in the same way in the definition of the same COMMON area in another program. However, the number of elements defined should be the same in both cases. It is best practice to defined COMMON areas via a single INCLUDE file in order to avoid using different definitions in different programs.
You can use the CLEARCOMMON statement to reset all of the variables in held in a common storage area.
The COMMON initialization of array variables for Caché MVBasic is UNASSIGNED, for both named and unnamed common storage areas. Other supported MultiValue emulations provide differing initialization for array variables in named and unnamed common storage areas. Scalar variables are always initialized as UNASSIGNED in all emulations.
The following example initializes an array variable in the unnamed common storage area, then tests whether the variable is assigned. In native Caché MVBasic the result will always be unassigned; other MultiValue emulations return other results.
COMMON c(3) IF ASSIGNED(c(3)) THEN PRINT c(3) ELSE PRINT "Unassigned for unnamed storage"
The following example initializes an array variable in a named common storage area, then tests whether the variable is assigned. In native Caché MVBasic the result will always be unassigned; other MultiValue emulations return other results.
COMMON /ABC/ y(2) IF ASSIGNED(y(2)) THEN PRINT y(2) ELSE PRINT "Unassigned for named storage"