Mainframe Path Start learning free
CoreError and abend codesONCODE 320

PL/I ZERODIVIDE (ONCODE 320) and CONVERSION (ONCODE 6xx)

A PL/I program raised a condition it did not handle. ONCODE tells you which one and why; an ON-unit lets you handle it instead of failing.

What happened

A PL/I program hit a run-time condition — a division by zero, or character data that could not be converted to a number. With no ON-unit for it, the implicit action applied: a run-time message was issued and the ERROR condition was raised, which normally ends the program under Language Environment.

Output from a program's own ON-unit (illustrative)Illustrative example
MPCALC01 CONDITION TRAPPED: ZERODIVIDE  ONCODE=320
MPCALC01 ACCOUNT=00012345  UNITS=0  - RECORD REJECTED
MPLOAD02 CONVERSION ERROR  ONCODE=601  ONSOURCE='12A4'  ONCHAR='A'

What it means

PL/I signals unusual events as named conditions. Each occurrence also has a numeric condition code, returned by the ONCODE built-in function inside an ON-unit (outside one it returns 0). IBM's Messages and Codes lists every code; two you will meet often:

ZERODIVIDE and CONVERSION are enabled by default, as are FIXEDOVERFLOW, OVERFLOW and INVALIDOP. SIZE, STRINGRANGE, STRINGSIZE and SUBSCRIPTRANGE are disabled by default and must be enabled with a condition prefix such as (SUBSCRIPTRANGE):.

Typical causes

Symptoms

Where to look

How to diagnose

  1. Note the condition name and the ONCODE.
  2. Find the statement from the message and the compile listing.
  3. For ZERODIVIDE, identify the divisor and where its value came from.
  4. For CONVERSION, use the ONSOURCE (whole field) and ONCHAR (failing character) values to see exactly what was rejected.

How to fix

Test the divisor before dividing, and decide with the business what a zero should mean. For conversions, validate input before using it as a number. Where the program must survive bad data, code an ON-unit: ON ZERODIVIDE to log and skip, or ON CONVERSION using the ONSOURCE and ONCHAR pseudovariables to substitute a valid value and continue.

ON-unit sketch (illustrative)Illustrative example
ON ZERODIVIDE BEGIN;
  PUT SKIP LIST('ZERODIVIDE ONCODE=', ONCODE(), ' ACCT=', ACCT_NO);
  REJECT_COUNT = REJECT_COUNT + 1;
  GO TO NEXT_RECORD;
END;

How to prevent

Production considerations

Interview question

What is ONCODE and where can you use it?

Stuck on something else?
Ask the community or search the full course.

Ask a question