ILE COBOL Programmer's Guide

Sharing EXTERNAL Data

Separately compiled ILE COBOL programs (including programs within a sequence of ILE COBOL source programs) can share data items by using the EXTERNAL clause. This EXTERNAL data is handled as weak exports. Refer to ILE Concepts for further information about strong and weak exports.

You specify the EXTERNAL clause on the 01-level data description in the Working-Storage Section of the ILE COBOL program, and the following rules apply:

  1. Items subordinate to an EXTERNAL group item are themselves EXTERNAL.
  2. The name used for the data item cannot be used on another EXTERNAL item within the same program.
  3. The VALUE clause cannot be specified for any group item, or subordinate item, that is EXTERNAL.
  4. EXTERNAL data cannot be initialized and its initial value at runtime is undefined. If your application requires that EXTERNAL data items be intialized, it is recommended that they are explicitly initialized in the main program.

Any ILE COBOL program within a run unit, having the same data description for the item as the program containing the item, can access and process the data item. For example, if program A had the following data description:

01 EXT-ITEM1          PIC 99 EXTERNAL.

Program B could access the data item by having the identical data description in its Working-Storage Section.

The size must be the same for the same named EXTERNAL data item in all module objects declaring it. If different sized EXTERNAL data items with the same name are declared in multiple ILE COBOL programs in a compilation unit, the longest size is used to represent the data item.

Also, when different sized EXTERNAL data items of the same name are represented in multiple program objects or service programs that are activated in the same activation group, and the later activated program object or service program has a larger size for the same named EXTERNAL data item, then the activation of the later activated program object or service program will fail.

The type consistency across data items of the same name that are declared in multiple ILE COBOL programs is not enforced by the ILE COBOL compiler. You are responsible for ensuring that the usage of these data items is consistent.

Remember, any program that has access to an EXTERNAL data item can change its value. Do not use this clause for data items you need to protect.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]