To handle a program error or exception you can write a program error subroutine
(*PSSR). When a program error occurs:
The program status data structure is updated.
If an indicator is not specified in positions
73 and 74 for the operation code, the error is handled and control is transferred
to the *PSSR.
You can explicitly transfer control to a program error subroutine
after a file error by specifying *PSSR after the keyword INFSR on the File
Description specifications.
You can code a *PSSR for any (or all) procedures in the module. Each *PSSR
is local to the procedure in which it is coded.
To add a *PSSR error subroutine to your program, you do the following steps:
Optionally identify the program status data structure (PSDS) by specifying
an S in position 23 of the definition specification.
Enter a BEGSR operation with a Factor 1 entry of *PSSR.
Identify a return point, if any, and code it on the ENDSR operation in
the subroutine. For subprocedures, factor 2 must be blank. For a discussion
of the valid entries for Factor 2, see Specifying a Return Point in the ENDSR Operation.
Code the rest of the program error subroutine. Any of the ILE RPG compiler
operations can be used in the program error subroutine. The ENDSR operation
must be the last specification for the program error subroutine.
Figure 1 shows an example of a program error subroutine
in a cycle-main procedure.
The program-status data structure is defined on the Definition specifications.
The predefined subfields *STATUS, *ROUTINE, *PARMS, and *PROGRAM are specified,
and names are assigned to the subfields.
The *PSSR error subroutine is coded on the calculation specifications.
If a program error occurs, ILE RPG passes control to the *PSSR error subroutine.
The subroutine checks to determine if the exception was caused by a divide
operation in which the divisor is zero. If it was, 1 is added to the divisor
(Divisor), and the literal ‘*DETC’ is moved to the field ReturnPt,
to indicate that the program should resume processing at the beginning of
the detail calculations routine
If the exception was not a divide by zero, the literal ‘*CANCL’
is moved into the ReturnPt field, and the procedure ends.
Figure 2 and Figure 3 show how you would code
similar program error subroutines in a subprocedure. In one example, you code
a GOTO and in the other you code a RETURN operation.