The CANCEL Statement

The CANCEL statement ensures that the next time the referenced program is called it is in its initial state.

General Format


CANCEL Statement

Directives:

  1. In addition to Compiler directives which provide flagging and modify the reserved word list, the following directives may impact either the syntax or the semantics described in this section.
    • DYNAM - NODYNAM causes CANCEL statements to be ignored.

Syntax Rules

  1. Literal-1 must be a nonnumeric literal.
  2. Identifier-1 must reference an alphanumeric data item.

General Rules

  1. Literal-1 or the content of the data item referenced by identifier-1 identifies the name of the program to be canceled. The name must contain the program-name contained in the Program-ID paragraph of the program to be canceled (see the section The Program-ID Paragraph in the chapter Identification Division, particularly in regard to case sensitivity). Alternatively, the name may identify a file that contains executable program code for the program to be canceled. The results of specifying different names that identify the same file in a CANCEL statement are operating-system specific. See your COBOL system documentation for details of how your system matches the given name to previously called programs, program filenames or programs held in library files.

    If the name contains the entry-name contained in an ENTRY statement, the results are undefined.

  2. Subsequent to the execution of an explicit or implicit CANCEL statement, the program referred to therein ceases to have any logical relationship to the run unit in which the CANCEL statement appears. If the program referenced by a successfully executed explicit or implicit CANCEL statement in a run unit is subsequently called in that run unit, that program is in its initial state. See the topic State of a Function, Method or Program in the chapter Language Fundamentals.
  3. A program named in a CANCEL statement in another program must be callable by that other program. See the topic Scope of Names in the chapter Concepts of the COBOL Language and the section The CALL Statement.
  4. ANS85 When an explicit or implicit CANCEL statement is executed, all programs contained in the program referenced by the CANCEL statement are also canceled. The result is the same as if a valid CANCEL statement were executed for each contained program in the reverse order in which the programs appear in the separate program.
  5. A program named in the CANCEL statement must not refer directly or indirectly to any program that has been called and has not yet executed an EXIT PROGRAM

    OSVSVSC2MF or GOBACK

    statement.

  6. A logical relationship to a canceled program is established only by execution of a subsequent CALL statement naming that program.
  7. A called program is canceled either by being referred to as the operand of a CANCEL statement, by the termination of the run unit of which the program is a member,

    ANS85 or by execution of an EXIT PROGRAM statement in a called program that possesses the initial attribute.

  8. No action is taken when an explicit or implicit CANCEL statement is executed naming a program that has not been called in this run unit, has been called and is at present canceled or is a non-COBOL program. Control is transferred to the next executable statement following the CANCEL statement.
  9. ANS85 The contents of data items in external data records described by a program are not changed when that program is canceled.
  10. ANS85 During execution of an explicit or implicit CANCEL statement, an implicit CLOSE statement without any optional phrases is executed for each file in the open mode that is associated with an internal file connector in the program named in the CANCEL statement. Any USE procedures associated with any of these files are not executed.
  11. The CANCEL statement determines whether or not a subprogram is re-entered in initial or last-used state. It does not necessarily free any memory used by the subprogram. However, in many operating systems, if the subprogram has been dynamically loaded, this statement also frees the memory originally used by the subprogram. EXTERNAL files and data areas of the subprogram are never freed by a CANCEL statement.