Special registers

Special registers are reserved words that name storage areas generated by the compiler. Their primary use is to store information produced through specific COBOL features. Each such storage area has a fixed name, and must not be defined within the program.

For programs with the RECURSIVE attribute, storage for the following special registers is allocated on a per-invocation basis:

  • ADDRESS OF
  • RETURN-CODE
  • SORT-CONTROL
  • SORT-CORE-SIZE
  • SORT-FILE-SIZE
  • SORT-MESSAGE
  • SORT-MODE-SIZE
  • SORT-RETURN
  • TALLY
  • XML-CODE
  • XML-EVENT
  • XML-NTEXT
  • XML-TEXT

For the first call to a program after a cancel of that program, the compiler initializes the special register fields to their initial values.

For the following two cases:
  • Programs that have the INITIAL clause specified
  • Programs that have the RECURSIVE clause specified
the following special registers are reset to their initial value on each program entry:
  • RETURN-CODE
  • SORT-CONTROL
  • SORT-CORE-SIZE
  • SORT-FILE-SIZE
  • SORT-MESSAGE
  • SORT-MODE-SIZE
  • SORT-RETURN
  • TALLY
  • XML-CODE
  • XML-EVENT

Further, in the above two cases, values set in ADDRESS OF special registers persist only for the span of the particular program invocation.

In all other cases, the special registers will not be reset; they will be unchanged from the value contained on the previous CALL.

Unless otherwise explicitly restricted, a special register can be used wherever a data-name or identifier that has the same definition as the implicit definition of the special register can be used. Implicit definitions, if applicable, are given in the specification of each special register.

You can specify an alphanumeric special register in a function wherever an alphanumeric argument to a function is allowed, unless specifically prohibited.

If qualification is allowed, special registers can be qualified as necessary to provide uniqueness. (For more information, see Qualification.)