!DupExit statement

From m204wiki
Revision as of 21:59, 25 August 2014 by JAL (talk | contribs)
Jump to navigation Jump to search

The !DUPEXIT statement conditionally closes the current procedure, and it continues compilation in the procedure (or command level statement) that INCLUDE'd the current procedure.

As such, !DUPEXIT is not a valid statement at command level. It conditionally closes the current procedure if the explicit or implicit macro variable is defined. If the macro variable is not defined, the variable is set to defined, and processing continues in the current procedure. !DUPEXIT really performs the work of two macro statements: !IFNDEF and !DEF

!DUPEXIT can, optionally, be followed by the name of a macro variable. If the macro variable name is not specified, it defaults to the name of the current procedure. In this latter case, the length of the procedure name must be less than the setting of the LAUDIT system parameter (unless the parameter is set to 255). !DUPEXIT can be useful for preventing one-time-only definitions (%variable or subroutine) from being performed more than once. For example, the !DUPEXIT statement in the following example prevents subroutine COMMON from being defined more than once, as long as the subroutine is only defined in procedure COMPLEX:

PROCEDURE COMPLEX !DUPEXIT SUBROUTINE COMMON(%INPUT IS FLOAT) . . . END SUBROUTINE END PROCEDURE

The first time COMPLEX is INCLUDE'd, the !DUPEXIT will not close COMPLEX (because COMPLEX will be undefined), but it will then define COMPLEX. Any subsequent time that COMPLEX is INCLUDE'd, the !DUPEXIT will cause it to be closed immediately, because at that point COMPLEX will be defined.

If subroutine COMMON might be defined in other procedures, COMPLEX might be changed as follows:

PROCEDURE COMPLEX !DUPEXIT COMMON SUBROUTINE COMMON(%INPUT IS FLOAT) . . . END SUBROUTINE END PROCEDURE

This tactic will only work as long as other procedures that define subroutine COMMON also:

  • Define it conditionally based on whether COMMON is defined.
  • Define COMMON if they define the subroutine.

This can be done with a !DUPEXIT or with a !IFNDEF and a !DEF.

See also