HP 3000 Manuals

Types of Subprograms [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

Types of Subprograms 

HP COBOL II has three kinds of subprograms:

   1.  Non-Dynamic.
   2.  Dynamic.
   3.  ANSISUB.
[REV BEG]

Specify which kind of subprogram you want by using one of the following:

          Table 11-1.  Types of Subprograms and How to Specify Them 

--------------------------------------------
|              |                           |
|  Subprogram  |     Option or Clause      |
|     Type     |                           |
|              |                           |
--------------------------------------------
|              |                           |
| Non-Dynamic. | $CONTROL SUBPROGRAM       |
|              |                           |
--------------------------------------------
|              |                           |
| Dynamic.     | $CONTROL DYNAMIC or the   |
|              | INITIAL clause of the     |
|              | PROGRAM-ID paragraph.     |
|              |                           |
--------------------------------------------
|              |                           |
| ANSISUB      | $CONTROL ANSISUB          |
|              |                           |
--------------------------------------------

[REV END]

See Appendix B , "$CONTROL Options," and Appendix H , for more
information on these options.

If you do not use one of these $CONTROL options and the source program
contains a LINKAGE SECTION, it is compiled as a non-dynamic subprogram.
A program containing no LINKAGE SECTION is considered a main program
unless $CONTROL SUBPROGRAM, DYNAMIC, or ANSISUB[REV BEG]  or PROGRAM IS 
INITIAL clause[REV END] is used for that program.

Non-Dynamic Subprograms 

Use $CONTROL SUBPROGRAM to specify a non-dynamic subprogram.  The data of
a non-dynamic subprogram is declared as OWN.[REV BEG] That is, the
subprogram data retain their values between calls to the subprogram.[REV
END]

In other words, when you exit a called non-dynamic subprogram, its state
is maintained.  Thus, data items not common to the calling program or a
program that called the calling program retain their values when the
program in which they are used is exited.

Dynamic Subprograms 
[REV BEG]

Use $CONTROL DYNAMIC or the INITIAL clause of the PROGRAM-ID paragraph to
specify a dynamic subprogram.  The INITIAL clause is part of the ANSI
standard.  Dynamic subprograms are equivalent to PROGRAM IS INITIAL
and[REV END] have local data storage and are always in their initial
state when[REV BEG] called.  This implies that any files opened in
dynamic subprograms should be closed before exiting.  Otherwise, the file
is closed for you.[REV END]

ANSISUB Subprograms 

Ansisub subprograms are the 1985 ANSI COBOL standard type of
subprogram.[REV BEG] Use $CONTROL ANSISUB to specify an ansisub
subprogram.[REV END] Ansisub subprograms are a combination of the dynamic
and non-dynamic types.  The data area of an ansisub subprogram retains
its values between calls unless you explicitly reinitialize the data
area.  To reinitialize an ANSISUB subprogram, use the CANCEL statement in
the calling program after the EXIT PROGRAM or GOBACK statement has been
executed in the ansisub subprogram.  See "MPE XL System Dependencies" in
Appendix H  for more information about using ansisub subprograms.

For more information on subprograms, see the HP COBOL II/XL Programmer's 
Guide.



MPE/iX 5.0 Documentation