Most operation codes support a status error code. When an operation code generates an exception/error, the program information data structure field *STATUS is updated. In addition, if the operation supports an error indicator (resulting indicator 2), that indicator is set on when an error is generated. Also, if the E operation extender is specified, the %STATUS built-in function is set to the status code listed in Table 5.13, and the %ERROR built-in function is set to *ON.
Code | Description of Conditions |
---|---|
00000 | No exception/error occurred. |
00001 | Called program ended with indicator LR on. |
00100 | String operation had range or subscript error. |
00101 | Square root of a negative number. |
00102 | Divide by zero. |
00121 | Invalid array index. |
00122 | OCCUR operation outside of data structure range. |
00202 | Called program failed with indicators H1 to H9 off. |
00211 | Program specified on CALL or FREE operation not found. |
00221 | Called program tried to access a parameter that was not passed to it. |
00231 | Called program failed with halt indicator (H1 to H9) on. |
00232 | Halt indicator (H1 to H9) on in current program. |
00233 | Halt indicator on when RETURN operation performed. |
00299 | RPG-formatted dump failed. |
00333 | Error occurred during DSPLY operation. |
00401 | Data area specified for IN/OUT operation not found. |
00402 | *PDA not valid for pre-start job. |
00411 | Attributes of data area specified for IN/OUT operation does not match actual data area. |
00412 | Data area specified for OUT operation was not locked. |
00413 | Error occurred during IN/OUT operation. |
00414 | Security authorization to access data area failed. |
00415 | Security authorization to change data area failed. |
00421 | Error occurred during UNLOCK operation. |
00431 | Data area is locked by another program and/or job. |
00432 | Data area is locked by another program in this job. |
00907 | Decimal data error. |
00970 | Compiler level does not match run-time subroutine level. |
09998 | Internal failure in RPG or generated run-time subroutines. |
09999 | Program exception in an operating system routine. |
Note: These codes apply to RPG IV on IBM OS/400 and might differ with other compilers. |
For operation codes that don't support the error indicator (e.g., SQRT, ADD, SUB, EVAL, MULT, DIV, MOVE, and MOVEA), the program exception/error subroutine (*PSSR) is automatically called (if it exists in the program). Example 5.1 illustrates how to code the *PSSR subroutine.
Example 5.1: Using the program status data structure to detect a divide-by-zero error.
.....DName+++++++++++EUDSFrom+++To/Len+TDc.Functions++++++++++++++++++++++++++++ 0010 D PSDS SDS 0020 D Status *STATUS 0040 D Fact1 S 3P 0 Inz(5) 0050 D Fact2 S 3P 0 Inz(0) 0060 D Answer S 3P 0 Inz(0) .....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq 0070 C Fact1 Div Fact2 ANSWER 0080 C MOVE *ON *INLR 0090 CSR *PSSR BEGSR 0100 C If Status = 102 0110 C Eval Answer = 999 0120 C EndIf 0130 CSR endPSSR ENDSR