Compaq COBOL AAQ2G1FTK User Manual

Page 440

Advertising
background image

Interprogram Communication
12.4 Accessing Another Program’s Data Division

Figure 12–3 Accessing Another Program’s Data Division

IDENTIFICATION DIVISION.

PROGRAM−ID. SUB.

ENVIRONMENT DIVISION.

DATA DIVISION.

LINKAGE SECTION.

01 PART PICTURE X.
01 AMOUNT PICTURE 9.
01 COST PICTURE 99.
01 COLOR PICTURE XX.

PROCEDURE DIVISION USING PART,

SUB−START−UP.

AMOUNT,

.
.
.

COLOR,

.
.
.

COST.

EXIT PROGRAM.

IDENTIFICATION DIVISION.

PROGRAM−ID. MAINPROG.

ENVIRONMENT DIVISION.

DATA DIVISION.

WORKING−STORAGE SECTION.

PROCEDURE DIVISION.

01 A PICTURE X.
01 B PICTURE 9.
01 C PICTURE XX.
01 D PICTURE 99.

.
.
.

CALL "SUB" USING A, B, C, D.

START−UP.

.
.
.

STOP RUN.

1

4

2

3

ZK−1731−GE

In Figure 12–3, when execution control transfers to SUB, it can access the four
data items in the calling program by referring to the data names in its Procedure
Division USING phrase. For example, the data names correspond as follows:

Data Name in
MAINPROG
(Calling Program)

Corresponding Data Name in SUB
(Called Subprogram)

A

PART

B

AMOUNT

C

COLOR

D

COST

The CALL statement can make data available to the called program by the
following argument-passing mechanisms:

REFERENCE—The address of (pointer to) the argument (arg) is passed to
the calling program. This is the default mechanism.

CONTENT—The address of a copy of the contents of arg is passed to the
called program. Note that since a copy of the data is passed, the called
program cannot change the original calling program data.

VALUE—The value of arg is passed to the called program. If arg is a data
name, its description in the Data Division can be as follows: ( a ) COMP usage
with no scaling positions (the PICTURE clause can specify no more than nine
digits) and ( b ) COMP-1 usage.

12–10 Interprogram Communication

Advertising