COBOL GLOBAL & EXTERNAL Variable


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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值