Reference to Common Data and Files through External Objects [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
Reference to Common Data and Files through External Objects
This is a feature of the 1985 ANSI COBOL standard
Accessible data items usually require that certain representations of
data be stored. File connectors usually require that certain information
concerning files be stored. The storage associated with a data item or a
file connector can be external or internal to the program in which the
object is declared.
A data item or file connector is external if the storage associated with
that object is associated with the run unit rather than with any
particular program within the run unit. An external object may be
referenced by any program in the run unit which describes the object.
References to an external object from different programs using separate
descriptions of the object are always to the same object. In a run unit,
there is only one representative of an external object.
An object is internal if the storage associated with that object is
associated only with the program that describes the object.
A data record described in the WORKING-STORAGE SECTION is given the
external attribute by the presence of the EXTERNAL clause in its data
description entry. Any data item described by a data description entry
subordinate to an entry describing an external record also attains the
external attribute. If a record or data item does not have the external
attribute, it is part of the internal data of the program in which it is
described.
A file connector is given the external attribute by the presence of the
EXTERNAL clause in the associated file description entry. If the file
connector does not have the external attribute, it is internal to the
program in which the associated file name is described.
The data records described subordinate to a file description entry that
does not contain the EXTERNAL clause or a sort-merge file description
entry, as well as any data items described subordinate to the data
description entries for such records, are always internal to the program
describing the file name. If the EXTERNAL clause is included in the
file description entry, the data records and the data items attain the
external attribute.
A file connector is given a global attribute by the presence of the
GLOBAL clause in the file description entry. By specifying the file
connector GLOBAL, all the data records associated with the file are
automatically given a global attribute and the record description entries
do not need to have a GLOBAL clause. However, if a GLOBAL clause is
specified in the record description entry and not in the file description
entry, only the record name is given a global attribute. For example,
the contained programs are not able to reference the file connector (no
file I/O is allowed), but are able to reference the record in which a
GLOBAL clause was specified.
Data records, subordinate data items, and various associated control
information described in the linkage of a program are always considered
to be internal to the program describing that data. Special
considerations apply to data described in the LINKAGE SECTION whereby an
association is made between the data records described and other data
items accessible to other programs.
If a data item possessing the external attribute includes a table
accessed with an index, that index does not possess the external
attribute.
PROGRAM-ID Paragraph
Define a subprogram using the PROGRAM-ID paragraph of the IDENTIFICATION
DIVISION.
Syntax.
Description.
For more information on the PROGRAM-ID paragraph, see Chapter 5 ,
"IDENTIFICATION DIVISION."
COMMON Clause.
The COMMON clause specifies that the program is common, a program
contained in another program. A common program is one which, though
contained within another program, may be called by any program directly
or indirectly contained in that other program. This clause is used in
nested and concatenated programs. It facilitates the writing of
subprograms which are to be used by all the programs contained within a
program.
EXTERNAL Clause
The EXTERNAL clause is a feature of the 1985 ANSI COBOL standard
The EXTERNAL clause specifies that a data item or a file connector is
external. The corresponding data items and data group items of an
external data record are available to every program in the run unit that
describes that record.
Syntax.
IS EXTERNAL
Description.
The EXTERNAL clause can only be specified in file description entries or
in record description entries in the WORKING-STORAGE SECTION.
The data-name specified as the subject of an entry with a level-number of
01 that includes the EXTERNAL clause must not be the same data-name
specified for any other data description entry that includes the EXTERNAL
clause.
The VALUE clause must not be used in any data description entry that
includes, or is subordinate to, an entry that includes the EXTERNAL
clause. The VALUE clause can be specified for condition-name entries
associated with these data description entries.
The data contained in the record named by the data-name clause is
external. It can be accessed and processed by any program in the run
unit that describes and, optionally, redefines it according to the
following rules.
* Within a run unit, if two or more programs describe the same
external data record, each record-name of the record description
entries must be the same. The records must define the same number
of standard data format characters.
However, a program describing an external record can contain a
data description entry that includes the REDEFINES clause. The
REDEFINES clause then redefines the complete external record.
This complete redefinition does not need to occur identically in
other programs in the run unit.
* The file connector associated with this description entry is an
external file connector.
Example.
The following example illustrates interprogram communication using
EXTERNAL items. A main program and a subprogram share an EXTERNAL file
and an EXTERNAL data item.
IDENTIFICATION DIVISION.
PROGRAM-ID. EXTITEMS.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SOUT ASSIGN TO "FILEOUTP".
DATA DIVISION.
FILE SECTION.
*
* THE EXTERNAL FILE SPECIFICATION
*
FD SOUT EXTERNAL.
01 REC-OUT.
05 NAME PIC X(20).
05 LOCN PIC X(10).
WORKING-STORAGE SECTION.
*
* THE EXTERNAL DATA-ITEM SPECIFICATION
*
* NOTE THAT SINCE THE ITEM IS 'EXTERNAL' THE VALUE
* CLAUSE MAY NOT BE USED EXCEPT WITHIN A CONDITION-NAME
* ASSOCIATED WITH THE DATA ITEM.
*
01 EXTERNAL-DATA-ITEM EXTERNAL PIC X(18).
88 X-ITEM VALUE "EXTERNAL-DATA-ITEM".
PROCEDURE DIVISION.
START-IT.
SET X-ITEM TO TRUE.
OPEN OUTPUT SOUT.
MOVE "JOHN DOE" TO NAME.
MOVE "BLDG 48 N" TO LOCN.
DISPLAY "DISPLAY OF EXT-DATA-ITEM FROM MAIN ** "
EXTERNAL-DATA-ITEM.
WRITE REC-OUT.
*
* CALL SUB1 TO WRITE A RECORD TO THE FILE. NOTE THAT
* THE EXTERNAL-DATA-ITEM VARIABLE IS NOT PASSED TO SUB1.
*
CALL "SUB1".
CLOSE SOUT.
*
* READ/DISPLAY THE SHARED FILE CONTENTS
*
OPEN INPUT SOUT.
READ-FILE-RECS.
READ SOUT AT END
CLOSE SOUT
STOP RUN.
DISPLAY REC-OUT.
GO TO READ-FILE-RECS.
$CONTROL SUBPROGRAM
IDENTIFICATION DIVISION.
PROGRAM-ID. SUB1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SOUT ASSIGN TO "FILEOUTP".
DATA DIVISION.
FILE SECTION.
FD SOUT EXTERNAL.
01 REC-OUT.
05 NAME PIC X(20).
05 LOCN PIC X(10).
WORKING-STORAGE SECTION.
01 EXTERNAL-DATA-ITEM EXTERNAL PIC X(18).
PROCEDURE DIVISION.
*
* NOTE THAT SUB1 DOES NOT REQUIRE A 'USING' CLAUSE TO
* ACCESS THE EXTERNAL DATA ITEM OR A FILE 'OPEN' TO
* ACCESS THE OUTPUT FILE.
*
START-IT.
MOVE "MARY JANE" TO NAME.
MOVE "BLDG 66 W" TO LOCN.
DISPLAY "DISPLAY OF EXT-DATA-ITEM FROM SUB1 ** "
EXTERNAL-DATA-ITEM.
WRITE REC-OUT.
GOBACK.
When this example is compiled using the ANSI85 entry point, and run, it
produces the following output:
DISPLAY OF EXT-DATA-ITEM FROM MAIN ** EXTERNAL-DATA-ITEM
DISPLAY OF EXT-DATA-ITEM FROM SUB1 ** EXTERNAL-DATA-ITEM
JOHN DOE BLDG 48 N
MARY JANE BLDG 66 W
GLOBAL Clause
The GLOBAL clause is a feature of the 1985 ANSI COBOL standard
The GLOBAL clause specifies that the data item or file connector can be
referenced by the contained programs within a nested program in which the
item is declared global.
Syntax.
IS GLOBAL
Description.
The following rules should be observed when using GLOBAL clause:
* The GLOBAL clause can only be specified in the file description
entries in the FILE SECTION or in the 01 record description
entries in the FILE SECTION and the WORKING-STORAGE SECTION.
* The GLOBAL clause can be specified in the record description
entries which have unique names.
* If the SAME RECORD AREA clause is specified for several files, the
record description entries or the file description entries for
these files must not include a GLOBAL clause.
* If the GLOBAL clause is used in a record description entry that
contains a REDEFINES clause, only the subject of the REDEFINES
clause will be given the global attribute.
* If the GLOBAL clause is used in a record description entry that
contains a table and index name, the index name is automatically
given the global attribute.
* If the GLOBAL clause is used in a record description entry that
contains a condition name defined with a level 88, the condition
name is automatically given the global attribute.
MPE/iX 5.0 Documentation