The program-name of a program is declared in the Program-ID paragraph of the program's Identification Division. A program-name can be referenced only by the CALL statement,
the CHAIN statement,
the CANCEL statement,
the SET statement
and the END PROGRAM header. If two programs in a run unit are identically named, at least one of those two programs must be directly or indirectly contained within a separate program which does not contain the other of those two programs.
The following rules regulate the scope of a program-name:
or, if the program possesses the recursive attribute, in the program itself
, except that the program possessing the common attribute and any programs contained within it may reference the program-name only if the program possesses the recursive attribute.
For example, suppose that ProgA contains ProgB and ProgC, ProgC contains ProgD and ProgF, and ProgD contains ProgE, as shown below.
If ProgD does not possess the COMMON attribute, then ProgD can only be referenced by the program that directly contains ProgD, that is, ProgC.
If ProgD does possess the COMMON attribute, then ProgD can be referenced by ProgC since it contains ProgD and by any programs contained in ProgC except for programs contained in ProgD, that is, by ProgF but not by ProgE. Also it cannot be referenced by ProgA or ProgB.