CANCEL Statement
The CANCEL
Statement causes a program to be returned to its initial state.
General Format:
CANCEL { program-1 } ...
Syntax:
program-n
is a program name, which may be expressed as a data element, literal, or data returned from a function call.
General Rules:
If a subprogram that does not contain the IS INITIAL PROGRAM
clause is the target of a CANCEL
verb, then the next time it is CALL
’ed, it is placed into its INITIAL
state.
Code Sample:
IDENTIFICATION DIVISION.
PROGRAM-ID. CANCEL-1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 DUMMY PIC X.
77 SUBPGM-NAME PIC X(5) VALUE "SUB-1".
PROCEDURE DIVISION.
CALL "SUB-1".
CANCEL "SUB-1".
DISPLAY "CALL/CANCEL [LITERAL]" LINE 7 COL 10.
CALL SUBPGM-NAME.
CANCEL SUBPGM-NAME.
DISPLAY "CALL/CANCEL [VARIABLE]" LINE 8 COL 10.
DISPLAY "CANCEL-1 COMPLETE!" LINE 10 COL 10.
ACCEPT DUMMY LINE 10 COL 30.
STOP RUN.
*
IDENTIFICATION DIVISION.
PROGRAM-ID. SUB-1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
DISPLAY "SUB-1 COMPLETE!" LINE 5 COL 10.
EXIT PROGRAM.