ON Statement

Defines the action to be taken when a specific condition is signaled during the execution of a program.

Syntax

Form 1:
ON condition–name ON-unit, 
Form 2:
ON condition–name SYSTEM

Parameters

condition-name
Any of the following:
  • ANYCONDITION
  • AREA
  • ATTENTION
  • CONDITION (name)
  • CONVERSION
  • ENDFILE(1)
  • ENDPAGE(1)
  • ERROR
  • FINISH
  • KEY(1)
  • OVERFLOW
  • RECORD(1)
  • ENDFILE(f)
  • ENDPAGE(f)
  • ERROR
  • FINISH
  • KEY(f)
  • OVERFLOW
  • RECORD(f)
  • SIZE
  • STRINGRANGE
  • UNDEFINEDFILE(f)
  • UNDERFLOW
  • USERCONDITION(expression)
  • USERCONDITION(SS$_UNWIND)
  • ZERODIVIDE
Note: For a description of each condition, see Open PL/I Conditions.
unit
A BEGIN block or any statement other than:
  • DECLARE
  • DEFAULT
  • DO
  • END
  • ENTRY
  • FORMAT
  • LEAVE
  • OTHERWISE
  • PROCEDURE
  • RETURN
  • SELECT
SYSTEM
Instead of executing user-specified code in the ON-unit, a system-generated message describing the condition is displayed and the ERROR condition is signaled.

Comments

  • ON is a compound statement, but it cannot be nested. The ON statement's use in responding to exceptional conditions is explained more fully in the section Statement that Handles Exception Conditions.
  • When specified, the STRINGRANGE condition is disabled in the program except within the scope of the STRINGRANGE condition prefix. For details on this condition, see the STRINGRANGE Condition topic in the IBM Language Reference.

Example

ON ENDFILE (F )
    BEGIN;
       .
       .
       .
    END;

In this example, the block of statements between the BEGIN and END statements executes if the end-of-file condition is reached.