Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the scope of COBOL

Tags:

scope

cobol

How is COBOL's scope defined? Is it statically scoped?

like image 820
NexAddo Avatar asked Feb 21 '11 19:02

NexAddo


2 Answers

Cobol has compile time binding for variables, sometimes called static scope.

Within that, Cobol supports several layers of scope within programs:

  • "External" variables are the equivilent of a Fortran or assembler common section, they are truly global.

  • "Global Program Scope" variables declared in working storage as global are visible to the entire program in which they are declared AND in all nested subprograms contained in that program.

  • "Program Scope" variables declared in working storage are visible to the entire program in which they are declared.

  • "Program Scope" variables declared in local storage are visible to the entire program in which they are declared, but are deleted and reinitialized on every invocation. Think thread scoped, sorta.

  • "Nested Program Scope" Cobol does not distinguish between programs and functions/procedures, its equvilent of a procedure or function is called a program. An infinite number of programs can be contained within a program, and the variables of each are visible only within the scope of that individual program. You could think of this as function/procedure scope.

The OO extensions that many vendors have, and the 2002 standard, defines the traditional public/protected/private object scope and method scope.

"Cobol" is as old as Radar, Laser, and Scuba, can we please stop acronymizing it?

like image 164
Joe Zitzelberger Avatar answered Sep 25 '22 16:09

Joe Zitzelberger


All variables in a COBOL program are globally scoped. In fact, there are no "scopes" (in traditional COBOL, I'm not messing with OO extensions), but just "modules" or "programs".

Intermodule communication is done via the Linkage Section (usually passed by ref), and also all variables there are visible from the called module.

like image 43
Dr. belisarius Avatar answered Sep 22 '22 16:09

Dr. belisarius