COBOL GLOBAL & EXTERNAL Variable

2019-04-15 15:48发布


GLOBAL Variable

GLOBAL in an enclosing program makes that variable visible to a nested program with it.
PROGRAM-ID.  Outer. WORKING-STORAGE SECTION. 01  Not-Global        PIC X. 01  Is-Global           PIC X GLOBAL. ...    CALL "Inner" ...    PROGRAM-ID.   Inner.           IF ( Not-Global .. )       <<-- error        IF ( Is-Global .. )          <<--- OK    END PROGRAM Inner. END PROGRAM Outer.

EXTERNAL Variable

EXTERNAL data may be defined in several _separately_compiled_ (or nested but you wouldn't) and statically or dynamically linked programs and these all refer to the same data area.  In other words the EXTERNAL data items are separate objects from the programs (they are created externally to the program) which are created by the first program containing them being loaded and are linked to by each subsequent program containing that block by name.
PROGRAM-ID.  ExternSamp. WORKING-STORAGE SECTION. 01  Is-Extern         PIC X EXTERN.
But an EXTERNAL variable cannot be defined with an initialization using VALUE clause; by default, all character variable will be initialized to whitespace, and numeric variable is initialized with zero.