Microsoft KB Archive/60856

Effects of the IS COMMON Clause on Nested Program CALLs

PSS ID Number: Q60856 Article last modified on 04-19-1990

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: Microsoft COBOL Compiler Versions 3.00 and 3.00a for MS-DOS and MS OS/2 allow for nested source programs; that is, a program definition entirely contained within another program definition. The nested program can be CALLed by the program in which it is nested in if the ANS85 and NESTCALL directives are used at compilation. However, if the nested program is to be called by any other nested programs, the IS COMMON clause must be used in its PROGRAM-ID paragraph. The rules outlined below describe what effects the IS COMMON clause has on nested program calling. This information applies to Microsoft COBOL Compiler Versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: By default, a nested program can only be called by the program in which it is nested, as the following diagram illustrates: FIRST-LEVEL SECOND-LEVEL-1 SECOND-LEVEL-2 FIRST-LEVEL can call both SECOND-LEVEL-1 and SECOND-LEVEL-2. However, SECOND-LEVEL-1 and SECOND-LEVEL-2 cannot call each other unless the IS COMMON clause is used, as follows: FIRST-LEVEL SECOND-LEVEL-1 IS COMMON SECOND-LEVEL-2 IS COMMON Now, beside FIRST-LEVEL being able to call SECOND-LEVEL-1 and SECOND-LEVEL-2, SECOND-LEVEL-1 and SECOND-LEVEL-2 can call each other. The following example shows doubly nested programs: FIRST-LEVEL SECOND-LEVEL-1 IS COMMON THIRD-LEVEL-1 IS COMMON THIRD-LEVEL-2 IS COMMON SECOND-LEVEL-2 IS COMMON THIRD-LEVEL-3 IS COMMON In this case, FIRST-LEVEL can still call SECOND-LEVEL-1 and SECOND-LEVEL-2. SECOND-LEVEL-1 and SECOND-LEVEL-2 can still call each other. THIRD-LEVEL-1 and THIRD-LEVEL-2 can call each other also. THIRD-LEVEL-3 can’t call any programs. FIRST-LEVEL cannot call any of the THIRD-LEVEL programs. Furthermore, neither SECOND-LEVEL-1 nor SECOND-LEVEL-2 can call the programs nested in the other. Also, THIRD-LEVEL-3 cannot call THIRD-LEVEL-1 or THIRD-LEVEL-2, and vice versa. However, THIRD-LEVEL-1 and THIRD-LEVEL-2 can call SECOND-LEVEL-2, just as THIRD-LEVEL-3 can call SECOND-LEVEL-1. Note that no program can call any program already included in the current sequence of calls (its own caller for example), nor can a program call itself. The following is a summary of the rules illustrated above: 1. By default (without the IS COMMON clause) a nested program can be called only by the program in which it is nested. 2. If a nested program is COMMON, it can also be called by the programs nested on the same level as it and the programs nested in those programs. 3. Even if a nested program is COMMON, it cannot be called by programs in which it is nested more than one level. Nor can it be called by the programs that are nested on the same level as the program in which it is nested. 4. No program may ever call itself or a program that is already included in the current sequence of calls. The following sample program demonstrates some of the ways nested programs can call each other: $SET NESTCALL $SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. FIRST-LEVEL. PROCEDURE DIVISION. DISPLAY “FIRST-LEVEL”. CALL “SECOND-LEVEL-1”. CALL “SECOND-LEVEL-2”. STOP RUN. IDENTIFICATION DIVISION. PROGRAM-ID. SECOND-LEVEL-1. PROCEDURE DIVISION. DISPLAY “SECOND-LEVEL-1”. CALL “SECOND-LEVEL-2”. CALL “THIRD-LEVEL-1”. EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. THIRD-LEVEL-1. PROCEDURE DIVISION. DISPLAY “THIRD-LEVEL-1”. CALL “SECOND-LEVEL-2”. CALL “FOURTH-LEVEL”. EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. FOURTH-LEVEL. PROCEDURE DIVISION. DISPLAY “FOURTH-LEVEL”. CALL “SECOND-LEVEL-2”. EXIT PROGRAM. END PROGRAM FOURTH-LEVEL. END PROGRAM THIRD-LEVEL-1. END PROGRAM SECOND-LEVEL-1. IDENTIFICATION DIVISION. PROGRAM-ID. SECOND-LEVEL-2 IS COMMON. PROCEDURE DIVISION. DISPLAY “SECOND-LEVEL-2”. CALL “THIRD-LEVEL-2”. EXIT PROGRAM. IDENTIFICATION DIVISION. PROGRAM-ID. THIRD-LEVEL-2. PROCEDURE DIVISION. DISPLAY “THIRD-LEVEL-2”. EXIT PROGRAM. END PROGRAM THIRD-LEVEL-2. END PROGRAM SECOND-LEVEL-2. END PROGRAM FIRST-LEVEL. The output of the program would be the following: FIRST-LEVEL SECOND-LEVEL-1 SECOND-LEVEL-2 THIRD-LEVEL-2 THIRD-LEVEL-1 SECOND-LEVEL-2 THIRD-LEVEL-2 FOURTH-LEVEL SECOND-LEVEL-2 THIRD-LEVEL-2 SECOND-LEVEL-2 THIRD-LEVEL-2

Copyright Microsoft Corporation 1990.