COM [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation
HP Business BASIC/XL Reference Manual
COM
The COM statement declares a common area. The common area is a global
data area that is first declared in the main program. One or more
variables can be declared in each declared common area. Each common
variable in a COM area declared in the main program unit is accessible
within the main program unit and in all called procedures or functions
that declare the common area in which the variable occurs. Unlike local
variables, the value of a common variable is retained following the exit
from a called procedure or function. A new common area can also be
declared in a called procedure or function if the GLOBAL OPTION
SUBPROGRAM NEWCOM or GLOBAL OPTION MAIN NEWCOM is used in the main
program area preceding the procedure or function. New common areas
declared in these routines are allocated when first encountered during
program execution and can be referenced in any routine called from that
routine. The common area is deallocated when the routine in which it was
allocated completes execution.
Syntax
COM [/identifier/] type_list [, type_list]...
Parameters
identifier Name of common area. If an identifier is specified,
the declared common area is "labeled" with the name
of the identifier. If an identifier is not
specified, then the common area is referred to as
the unnamed common area. You can have a maximum of
ten named commons and one unnamed common.
COM statements in different program units with the
same label refer to the same common area and unnamed
COM statements refer to the unnamed common area.
This identifier is truncated to eight characters.
{[type]num_com_item [, num_com_item]...}
type_list {non_num_com_item }
type One of the following:
SHORT INTEGER
INTEGER
SHORT DECIMAL
DECIMAL
SHORT REAL
SHORT
REAL
unspecified
If a type is not specified, implicit declaration
rules apply. After type, each num_com_item is of
that type until another type or a non_num_com_item
appears.
num_com_item Numeric variable declaration (for a scalar or array
variable).
If the COM statement is in a subunit, num_com_item
must represent a numeric array with the abbreviation
identifier([*[,*]...])
with one asterisk per dimension or without
asterisks. Not using asterisks specifies any number
of dimensions. Either format is legal, but the
format without asterisks is noncompilable. To
facilitate program documentation, numeric values can
be used in place of the asterisks, but these values
are ignored during program execution.
non_num_com_item String variable declaration (for a scalar or array
variable) or file designator. If maximum length is
not specified for a string variable, it is 18.
Maximum length is not specified if the COM statement
is in a subunit.
If the COM statement is in a subunit,
non_num_com_item must represent a string array with
the abbreviation
identifier$([*[,*]...])
with one asterisk per dimension or without
asterisks. Not using asterisks specifies any number
of dimensions. Either format is legal, but the
format without asterisks is noncompilable. The
maximum length of each element is the same as
declared in the main program. To facilitate program
documentation, numeric values can be used in place
of the asterisks, but these values are ignored
during program execution.
The syntax of an HP Business BASIC/XL file number
is:
#numeric_literal
numeric_literal is a positive integer in the range
[1, 32767]. The file designated by the actual
parameter in the COM area is referenced by
#numeric_literal within the subunit declaring the
com area. If the main procedure or function in
which the HP Business BASIC/XL file number occurs is
to be compiled, the numeric_literal must be a
positive integer in the range [1, 16].
To make it easier to copy com area to subunits, the declaration of the
com area in the main program can be copied directly to the subunit. The
numeric values specifying the range of subscripts for a dimension for
either numeric or string array variables do not need to be changed to
asterisks. However, HP Business BASIC/XL interprets the values as place
holders for each dimension. The dimension information in the common area
in the program unit in which the common area is declared, usually the
main, is used to determine the array dimensionality and the subscript
bounds.
Example 1: Common Declarations
10 COM INTEGER A,B, REAL C,D, A$[7], P,Q, DECIMAL X,Y,Z, #2
Variable(s) Type
A,B Integer
C,D Real
A$ String with maximum length of 7 characters
P,Q Default numeric type
X,Y,Z Decimal
#2 File designator
100 COM N,S$,N_array(1:5),S_array$(1:2,1:4)[6]
Variable(s) Type
N Default numeric type
S$ String with default maximum length (18)
N_array Array of default numeric type
S_array$ Array of strings with maximum length of 6
Example 2: Concatenation of Common Variable Lists If two COM statements
in the same program unit have the same area name, their variable lists
are concatenated.
Lines 200 and 210 are equivalent to line 300. Common area Area 3
contains the same variables whether the program unit contains lines 200
and 210 or line 300.
200 COM /Area3/ SHORT INTEGER J,K,L
210 COM /Area3/ REAL M,N,O, DECIMAL P,Q
300 COM /Area3/ SHORT INTEGER J,K,L, REAL N,N,O, DECIMAL P,Q
Example 3: Correspondence of Common Variables in Main and Subunit When
two program units declare the same common area, corresponding common
items refer to the same entities. The entities (for example, variables
or files) can have different names in different program units, however,
because the different names refer to the same areas in memory, they must
have the following:
* The same type.
* The same number of dimensions.
If the main program unit contains the statements:
10 COM /Area4/ REAL A,B$[60], INTEGER C, #8
20 COM /Area4/ DECIMAL E(1:25,1:50), F$(0:4,0:4,0:4)[12]
Then a subunit can contain the statements:
350 COM /Area4/ REAL X,Y$
360 COM /Area4/ INTEGER C, #10, DECIMAL E()
370 COM /Area4/ F$(*,*,*)
Corresponding variables are compatible:
Main Program Unit Program Subunit
REAL A REAL X
B$[60] Y$
INTEGER C INTEGER C
# 8 # 10
DECIMAL E(1:25,1:50) DECIMAL E()
F$(0:4,0:4,0:4)[12] F$(*,*,*)
If the main program unit assigns a value to the variable that it calls A,
and then calls the program subunit, the value of X is the same as that
assigned to A in the main because A and X are different names for the
same variable.
If the main program unit contains the statements:
10 COM /Area4/ SHORT REAL A, B$[60], INTEGER C, #15
20 COM /Area4/ DECIMAL E, F$(0:4,0:4,0:4)[12]
Then a procedure in the same program cannot contain the statements:
450 COM /Area4/ REAL Num, String$, SHORT INTEGER D
460 COM /Area4/ Q$, DECIMAL A(*,*), B()
The conflict in type and /or dimension for each variable is:
Main Program Unit Program Subunit
SHORT REAL A REAL Num
INTEGER C SHORT INTEGER D
#15 Q$
DECIMAL E DECIMAL A(*,*)
F$(0:4,0:4,0:4)[12] B()
Within a program unit, the following variables cannot have the same name:
* A common scalar variable and a local scalar variable.
* A common array variable and a local array variable.
In most cases, the main program declares every common area that the
program uses, whether the main program uses it or not. Before HP
Business BASIC/XL executes the main program unit, it allocates space for
all common variables, using the default numeric type and default lower
bound set by GLOBAL OPTION statements.
A procedure need only declare the common areas that it uses. A procedure
can declare all or part of the defined common area (starting at the
beginning), but cannot add items to it.
Exceptions to the foregoing occur if the NEWCOM suboption of the
MAIN/SUBPROGRAM global option is used. If NEWCOM is specified in the
current procedure, then, when the procedure begins execution, new common
areas in the subunit that are not declared in the main program are
allocated space. Also, the space for common areas declared in the main
program that are not used in the procedure is deallocated.
Examples
If the main program unit contains the COM statements:
10 COM /Area5/ INTEGER A,B, REAL C,D, DECIMAL E,F
20 COM /Area5/ A$,B$,C$
Then a procedure can declare all of Area5:
100 COM /Area5/ INTEGER X,Y
110 COM /Area5/ REAL R1,R2
120 COM /Area5/ DECIMAL D1,D2
130 COM /Area5/ A$, B$, C$
Or part of Area5, starting at the beginning:
200 COM /Area5/ INTEGER Part1,Part2, REAL Part3, Part4
210 COM /Area5/ DECIMAL D
But a procedure cannot omit the beginning of Area5:
300 COM /Area5/ REAL P,Q
310 COM /Area5/ DECIMAL D1,D2
And it cannot add to Area5:
400 COM /Area5/ INTEGER Int1,Int2, REAL Real1,Real2
410 COM /Area5/ DECIMAL Dec1, Dec2, A$, B$, C$
420 COM /Area5/ SHORT Sh1, Sh2, Sh3
Common variables are initialized as explained in "Initializing
Variables," in chapter 3.
MPE/iX 5.0 Documentation