COBOL Manual for TNS and TNS/R Programs
Program Compilation
HP COBOL Manual for TNS and TNS/R Programs—522555-006
11-133
TRAP2 and NOTRAP2
NOTRAP2
specifies that the compiler does not expect the operating environment to trap
arithmetic overflow in the current program. If the current program was called from
an environment in which trapping was enabled, however, programs that the current
program calls will have trapping enabled (unless overridden by the NOTRAP2-74
directive).
In object code produced by the HP COBOL 74 compiler, if a size error condition occurs
in an arithmetic operation for which no SIZE ERROR phrase is present, the
computation produces an undefined result (unpredictable value).
In object code produced by the COBOL85 compiler, if a size error condition occurs in
an arithmetic operation that is not within a statement that has a SIZE ERROR phrase,
the program suspends execution with a trap 2 (arithmetic overflow) condition. In the
CRE, if the command PARAM INSPECT ON is active, the process enters the selected
debugger (see Debugger Selection); if PARAM INSPECT OFF is active, it does not. In
the non-CRE environment, the process enters the selected debugger unless the
program calls the COBOL85^ARMTRAP routine.
Trapping behavior is governed by the trap-enable bit in the environment register of
each process. The process uses this bit to direct the hardware whether or not to trap
arithmetic overflows. The initialization routines of HP COBOL (executed by the main
program when the process is starting up) request the trapping; those of a COBOL 74
main program suppress the trapping. When there are no TRAP2 or TRAP2-74
directives present, nothing in the generated code or the run-time routines changes the
trap-enable bit.
When an HP COBOL program is compiled with the NOTRAP2 directive active, the
compiler generates code at the beginning of each HP COBOL program (including
nested programs) to record the value of the trap-enable bit, and to clear that bit if it was
set. Furthermore, it localizes the trap suppression to just the current routine. Before
each CALL or ENTER that the program executes, if the recorded setting is “use
trapping,” the compiler generates code to set the bit before executing the call and to
clear the bit again when control returns to the current program.
Default: TRAP2
Placement: Anywhere
Scope: The last TRAP2 or NOTRAP2 before the END PROGRAM statement for
the outermost program applies to the entire separately compiled
program (the outermost program of a compilation and any programs
contained within it).
Dependencies: NOTRAP2-74 overrides TRAP2.
References: TRAP2-74 and NOTRAP2-74