Previous Topic: Program Layout

Next Topic: Copy Books

Declaration of Variables

Modularize variable declarations. At the main procedure level, only declare those variables that are true global variables. Declare other variables within the appropriate block: do not give variables a wider scope than is necessary.

It is generally preferable not to factorize variable declarations, as it makes it harder to scan for the existence of a particular variable declaration.

Not:

But rather:

Include explanations of variables as comments on the DCL statement.

For structured variables, use level numbers, such as 1, 5, 10, and 15. This allows for subsequent insertion of new levels.

The prefix of a variable should denote its scope.

Each file declaration should be preceded by a comment naming the contents of the file. For logical files, the access path will preferably be indicated. Declare the file and its related control data structures, such as record, key, and return code, together. This facilitates the copying of code.

It is essential to have the same file usage throughout all programs that will form a single run unit. If file usages conflict, an execution time error is almost inevitable. For example, not as follows: