COBOL GLOBAL & EXTERNAL Variable

来源:互联网 发布:矩阵乘法结合律证明 编辑:程序博客网 时间:2024/05/22 05:31


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) whichare 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.

0 0
原创粉丝点击