How is COBOL's scope defined? Is it statically scoped?
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With