Program Structure

Each program is viewed by the operating system as having a certain block structure. The block structure of the program can have implications for the critical block definition and for the ability of processes to communicate through global objects. For further information on these topics, refer to “Critical Blocks” in Understanding Interprocess Relationships and to Using Global Objects.

The term flow of control refers to the order in which the statements of a program are executed. Most statements perform an action and then pass control to the immediately following statement. However, some statements can pass control to structures residing elsewhere in the program.

A block is a program, or program subunit, that can contain a group of declarations and a group of statements. The declarations create objects that are for local use by the statements in the block. There are two kinds of blocks: procedures and simple blocks.

A procedure is a block that can be executed using a procedure invocation statement, which passes control to the start of the procedure. When the procedure finishes executing, control automatically returns to the procedure invocation statement, and passes to the next statement in the program.

This abstract definition of a procedure corresponds to the way procedures are viewed by the operating system. Procedures are called by different names in the syntax of the various programming languages. This definition of a procedure corresponds, for example, to a PROCEDURE in ALGOL, a PROCEDURE or FUNCTION in Pascal, or a SUBROUTINE or FUNCTION in FORTRAN77. It also corresponds to a complete program written in any of these languages.

Note that a complete program written in COBOL is also considered a procedure. However, a paragraph or a section in COBOL is not considered a procedure. It is true that a PERFORM statement resembles a procedure invocation statement in that it causes control to pass through the paragraph or section and then return to the PERFORM statement. However, paragraphs and sections cannot include declarations and thus are not treated as procedures by the operating system. Therefore, the various properties of procedures discussed in this guide do not apply to paragraphs or sections.

Similarly, COBOL85 nested programs are not currently treated as procedures by the operating system. However, this implementation is subject to change. In future versions of COBOL85, nested programs might be treated like blocks.

A simple block is a block that cannot be specified in a procedure invocation statement. Simple blocks exist only in ALGOL, where they appear among the statements in the program, rather than among the declarations. The beginning and end of a simple block are marked by the keywords BEGIN and END. A simple block is executed in sequence between the statements that immediately precede and follow the simple block.

Note that a BEGIN...END group is considered to be a simple block only if it contains at least one declaration. Otherwise, it is considered a compound statement. Compound statements do not affect tasking or interprocess communication issues, and will not be further discussed in this guide.

Some languages, including WFL and ALGOL, allow blocks to be declared within other blocks. This practice is referred to as nesting. A block that contains a nested block is said to be global to that nested block. The most global block is referred to as the outer block of the program.

The lexical level of a block is a measure of how deeply the block is nested. By default, the outer block of a program has a lexical level of 2; however, compiler control options can be used to cause the outer block to be compiled with a higher lexical level. Each procedure has a lexical level one higher than the outer block or procedure in which it is declared.

ALGOL and NEWP support special TYPE declarations called structure blocks and connection blocks. Either of these declarations creates a data type consisting of a group of objects of possibly varying types. Note that structure blocks and connection blocks are not considered blocks in the sense that the term block is used in this book.