BEGSR *PSSR; declares the program-wide error subroutine. Any unhandled program
exception transfers control to *PSSR, which typically reports the error and ends
the program cleanly rather than letting it fail with a function check.
The ENDSR that closes an error subroutine may specify a return-point value to control what happens after the subroutine completes:
| Return point | Behavior |
|---|---|
| (blank) | Default - returns from the error handler |
'*CANCL' |
Cancels the program (throws RpgCancelException) |
'*DETC' / '*DETL' / '*GETIN' / '*TOTC' / '*TOTL' / '*OFL' |
Resumes the cycle at that step |
A runtime-determined return point - a variable or named constant holding the step name - is rejected with TRN1019.
// Free-format
BEGSR *PSSR;
DSPLY 'Error occurred';
ENDSR '*CANCL';
// Fixed-format
C *PSSR BEGSR
C 'Error!' DSPLY
C ENDSR '*CANCL'
A blank return point, '*CANCL', and the literal cycle-step resume points
(*DETC, *DETL, *GETIN, *TOTC, *TOTL, *OFL) are all supported. A
runtime-determined return point - a field, named constant, or array element
holding the step name - is rejected at compile time with TRN1019 rather than
silently returning to the default point (which would change control flow after
error handling). Use a literal cycle step or a blank return point.