HP 3000 Manuals

Calling COBOL Subprograms [ HP COBOL II/XL Programmer's Guide ] MPE/iX 5.0 Documentation


HP COBOL II/XL Programmer's Guide

Calling COBOL Subprograms 

When your COBOL program calls a subprogram written in COBOL, you should
understand the following:

       [REV BEG]

   *   What type the subprogram is.

   *   How your program passes the actual parameters.

   *   Whether or not the subprogram uses the RETURN-CODE special
       register.[REV END]

   *   When the calls to the COBOL subprogram will be bound to its
       definition.

   *   Whether to put the subprogram in a library, and if so, what kind
       of library.

Types of Subprograms 
[REV BEG]

HP COBOL II/XL has three kinds of subprograms:

   1.  Non-Dynamic.
   2.  Dynamic.
   3.  ANSISUB.

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

          Table 4-2.  Types of Subprograms and How to Specify Them 

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

For a description of these subprogram types, see the chapter
"Interprogram Communication" in the HP COBOL II/XL Reference Manual.[REV
END]

When none of the subprogram options above is specified, the COBOL
compiler uses the following rules to determine what type the program is:

   *   If the program is the first or only program in the source file,
       and the program contains a LINKAGE SECTION, it is assumed to be a
       non-dynamic subprogram.

   *   If the program is not the first program in the file (that is, if
       it is nested or concatenated) then it[REV BEG] is assumed to be a
       non-dynamic subprogram.

   *   If the program is the first or only program in the file and it has
       no LINKAGE SECTION, it is assumed to be a main program.[REV END]

Only the first program in the source file can be a main program.
However, the first program is compiled as a subprogram if you specify any
of the subprogram options listed in Table 4-2 .

Table 4-3  compares some of the attributes of subprograms. 

          Table 4-3.  Comparison of Non-Dynamic, Dynamic, and ANSISUB Subprograms 

-----------------------------------------------------------------------------------------
|                           |                   |                   |                   |
|      Characteristic       |    Non-Dynamic    |      ANSISUB      |      Dynamic      |
|                           |                   |                   |                   |
-----------------------------------------------------------------------------------------
|                           |                   |                   |                   |
| Initialized:              |   Once, at link   |   Once, at link   |   Each time the   |
|                           |       time.       |       time.       |   subprogram is   |
|                           |                   |                   |      called.      |
|                           |                   |                   |                   |
-----------------------------------------------------------------------------------------
|                           |                   |                   |                   |
| Affected by the CANCEL    |        No         |        Yes        |        No         |
| statement?                |                   |                   |                   |
|                           |                   |                   |                   |
-----------------------------------------------------------------------------------------

Non-dynamic subprograms and ANSISUB subprograms are initialized once, at
link time.  Therefore, data in the WORKING-STORAGE SECTION retain their
values between calls and files remain open between calls.

Dynamic subprograms are initialized every time the subprogram is called.
Therefore, data in the WORKING-STORAGE SECTION do not retain their values
between calls and files are closed between calls.  Dynamic subprograms
are not affected by the CANCEL statement.  Therefore, they do not contain
code to handle the CANCEL statement.  Dynamic subprograms are smaller
than ANSISUB subprograms.

If a program contains an INITIAL clause and the control option SUBPROGRAM
or ANSISUB, the INITIAL clause takes precedence.



MPE/iX 5.0 Documentation