2 the global clause – Compaq COBOL AAQ2G1FTK User Manual

Page 445

Advertising
background image

Interprogram Communication

12.5 Communicating with Contained COBOL Programs

PROG-MAIN (

1

) can call PROG-NAME-B (

2

) because PROG-MAIN directly

contains PROG-NAME-B. PROG-NAME-B (

2

) can call PROG-NAME-D (

3

)

because PROG-NAME-B directly contains PROG-NAME-D.

PROG-NAME-C (

4

) can call PROG-NAME-B (

2

) because:

PROG-NAME-C is not contained in PROG-NAME-B

PROG-NAME-B has the common attribute

PROG-NAME-C is contained by PROG-MAIN

However, PROG-NAME-D (

3

) cannot call PROG-NAME-B (

2

) because PROG-

NAME-D (

3

) is contained within PROG-NAME-B (

2

). Similarly, PROG-NAME-D

(

3

) cannot call PROG-NAME-C (

4

) because PROG-NAME-C (

4

) is not visible

to PROG-NAME-D (

3

). If PROG-NAME-C (

4

) was made COMMON it could

call PROG-NAME-D (

3

). Additionally, PROG-NAME-C (

4

) cannot call PROG-

NAME-D (

3

) because PROG-NAME-C (

4

) is outside the scope of PROG-NAME-B

(

2

).

12.5.2 The GLOBAL Clause

Data and files can be described as either global or local. A local name can be
referenced only by the program that declares it. A global name is declared in
only one program but can be referenced by both that program and any program
contained in the program that declares the global name.

Some names are always global, other names are always local, and some names
are either local or global depending on specifications in the program that declares
the names. For more information on Scope of Names rules, see the Compaq
COBOL Reference Manual
.

12.5.2.1 Sharing GLOBAL Data

A data name is global if the GLOBAL clause is specified in the Data Description
entry by which the data name is declared or in another entry to which that
Data Description entry is subordinate. If a program is contained within another
program, both programs may reference data possessing the global attribute. The
following example shows the Working-Storage Section of a containing program
MAINPROG. Any contained program in MAINPROG, as well as program
MAINPROG, can reference that data (unless the contained program declares
other data with the same name).

WORKING-STORAGE SECTION.
01

CUSTOMER-FILE-STATUS

PIC XX

GLOBAL.

01

REPLY

PIC X(10)

GLOBAL.

01

ACC-NUM

PIC 9(18)

GLOBAL.

12.5.2.2 Sharing GLOBAL Files

A file connector is global if the GLOBAL clause is specified in the File Description
entry for that file connector. If a program is contained within another program,
both programs may reference a file possessing the global attribute. The following
example shows a file (CUSTOMER-FILE) with the GLOBAL clause in a
containing program MAINPROG. Any contained program in MAINPROG, as
well as program MAINPROG, can reference that file.

Interprogram Communication 12–15

Advertising