Compaq AAQ2G1FTK Marine Radio User Manual


 
Interprogram Communication
12.3 Transferring Flow of Control
Example 12–5 Sequence of Messages Displayed When Example 12–4 Is Run
1. MAINPROG has control first.
2. MAINPROG transfers control to SUB1
upon executing the following CALL.
3. This is the entry point to SUB1.
4. SUB1 now has control.
5. SUB1 transfers control to SUB2.
6. This is the entry point to SUB2.
7. SUB2 now has control.
8. SUB2 returns control to SUB1
after executing the following
EXIT PROGRAM statement.
9. SUB1 regains control
10. after executing the following
EXIT PROGRAM statement.
11. MAINPROG has control last.
12. MAINPROG terminates the entire image upon
execution of the STOP RUN statement.
12.3.3 The EXIT PROGRAM Statement
To return control to the calling program, the called subprogram executes an EXIT
PROGRAM statement.
You can include more than one EXIT PROGRAM statement in a subprogram.
However, if it appears in a consecutive sequence of imperative statements, the
EXIT PROGRAM statement must appear as the last statement of the sequence.
For example:
IF A = B DISPLAY "A equals B", EXIT PROGRAM.
READ INPUT-FILE AT END DISPLAY "End of input file"
PERFORM END-OF-FILE-ROUTINE
EXIT PROGRAM.
If you do not include an EXIT PROGRAM statement in a subprogram, the
compiler generates one at the end of the program.
On executing an EXIT PROGRAM statement in a called subprogram, control
returns to the statement following the calling program’s CALL statement or the
first imperative statement in a NOT ON EXCEPTION clause specified for that
CALL statement.
On executing an EXIT PROGRAM statement in a main program, the EXIT
PROGRAM is ignored and control continues with the next statement.
Figure 12–2 shows how control is passed between programs.
12.4 Accessing Another Program’s Data Division
In a multiple COBOL program run unit, a called subprogram can access some of
its calling program’s Data Division. The calling program controls how much of it
will be accessible to the called subprogram in the following ways:
The USING phrase in both the CALL statement and the Procedure Division
header (see Section 12.4.1)
The Linkage Section (see Section 12.4.2)
The EXTERNAL clause (see Section 12.2.2)
12–8 Interprogram Communication