Effect of EXIT PROGRAM, STOP RUN, GOBACK, and CANCEL on Internal Files
The following statements affect the state of a file differently:
- An EXIT PROGRAM statement does not change the status
of any of the files in a run unit unless:
- The ILE COBOL program issuing the EXIT PROGRAM has the INITIAL attribute. If it has the INITIAL attribute, then all internal files defined in that program are closed.
- An EXIT PROGRAM statement with the AND CONTINUE RUN UNIT phrase is issued in the main program of a *NEW activation group. In this case, control returns from the main program to the caller, which, in turn, causes the *NEW activation group to end, closing all of the files scoped to the activation group.
- A STOP RUN statement returns control to the caller of the program at the nearest control boundary. If this is a hard control boundary, the activation group (run unit) will end, and all files scoped to the activation group will be closed.
- A GOBACK statement issued from a main program (which is always at a hard control boundary) behaves the same as the STOP RUN statement. A GOBACK statement issued from a subprogram behaves the same as the EXIT PROGRAM statement. It does not change the status of any of the files in a run unit unless the ILE COBOL program issuing the GOBACK has the INITIAL attribute. If it has the INITIAL attribute, then all internal files defined in that program are closed.
- A CANCEL statement resets the storage that contains information about the internal file. If the program has internal files that are open when the CANCEL statement is processed, those internal files are closed when that program is canceled. The program can no longer use the files unless it reopens them. If the canceled program is called again, the program considers the file closed. If the program opens the file, a new linkage to the file is established.