Example in OPM RPG: Logging software error (OPM API without pointers)

This program performs a divide-by-0 operation to cause an exception. This exception is caught using RPG *PSSR support, and the exception is then logged as a software error.

Refer to Example in ILE C: Logging software error (OPM API without pointers) for the original example.

Note: Read the Code license and disclaimer information for important legal information.
     F****************************************************************
     F*
     F* Program:        Demonstrate use of OPM-based Log Software Error
     F*
     F* Language:       OPM RPG
     F*
     F* Description:    This program performs a divide-by-0 operation
     F*                 to cause an exception.  This exception is
     F*                 caught using RPG *PSSR support,
     F*                 and the exception is then logged as a
     F*                 software error.
     F*
     F* APIs used:      QPDLOGER
     F*
     F****************************************************************
     E*
     E* Arrays used to extract source line number where error happened
     E*
     E                    SRC         8  1
     E                    TGT         8  1
     I*
     I* Error Code parameter include.  As this sample program uses
     I* /COPY to include the error code structure, only the first
     I* 16 bytes of the error code structure are available.  If the
     I* application program needs to access the variable length
     I* exception data for the error, the developer should physically
     I* copy the QSYSINC include and modify the copied include to
     I* define additional storage for the exception data.
     I*
     I/COPY QSYSINC/QRPGSRC,QUSEC
     I*
     I* Define Program Status Data Structure
     I*
     IPSDS       SDS
     I                                        1  10 PGMNAM
     I                                       11  150STATUS
     I                                       21  28 SRC
     I                                       40  46 EXCPID
     I                                       81  90 LIBNAM
     I*
     I* Some miscellaneous fields
     I*
     IMISC        DS
     I                                    B   1   40FAILPT
     I                                    B   5   80DATA#
     I                                    B   9  120OBJS#
     I                                       13  20 TGT
     I                                       13  200LIN#C
     I*
     I* DATA represents the data items to report as part of problem
     I*
     IDATA        DS                           4096
     I*
     I* DATAPT defines (via offset and length values) how to read DATA
     I*
     IDATAPT      DS                            256
     I                                    B   1   40DTAOFF
     I                                    B   5   80DTALEN
     I*
     I* OBJS represents the list of objects to spool as part of problem
     I*
     IOBJS        DS                           2590
     I                                        1  30 OBJ1N
     I                                       31  60 OBJ1L
     I                                       61  70 OBJ1T
     C*
     C* Prepare for divide-by-zero situation
     C*
     C                     Z-ADD10        FACT1   50
     C                     Z-ADD0         FACT2   50
     C*
     C* and divide by 0
     C*
     C           FACT1     DIV  FACT2     RESULT  50
     C*
     C* should not get here due to divide-by-0 exception
     C*
     C                     MOVE '1'       *INLR
     C                     RETRN
     C*
     C* Program exception subroutine:
     C*
     C           *PSSR     BEGSR
     C*
     C* Make sure we are not catching an exception due to the *PSSR
     C* subroutine itself
     C*
     C           SWITCH    IFEQ ' '
     C                     MOVE '1'       SWITCH  1
     C*
     C* Set API error code to work in nonexception mode
     C*
     C                     Z-ADD16        QUSBNB
     C*
     C* Record the source listing line number that caused the failure
     C*
     C*      First, extract the numeric portion of the PSDS line number
     C*
     C                     Z-ADD8         X       10
     C                     Z-ADD8         Y       10
     C                     Z-ADD0         LIN#C
     C           SRC,X     DOWEQ' '
     C                     SUB  1         X
     C                     END
     C           X         DOWGT0
     C                     MOVE SRC,X     TGT,Y
     C                     SUB  1         X
     C                     SUB  1         Y
     C                     END
     C*
     C*      Then record it:
     C*
     C                     Z-ADDLIN#C     FAILPT
     C*
     C* Record the status code for the failure
     C*
     C                     MOVELSTATUS    DATA
     C*
     C* Record where to find the status data within DATA
     C*
     C                     Z-ADD0         DTAOFF
     C                     Z-ADD5         DTALEN
     C                     Z-ADD1         DATA#
     C*
     C* For illustration purposes also dump the program object as
     C* part of logging the software error
     C*
     C                     MOVELPGMNAM    OBJ1N                 (1)
     C                     MOVELLIBNAM    OBJ1L
     C                     MOVEL'*PGM'    OBJ1T
     C                     Z-ADD1         OBJS#
     C*
     C* Call the Log Software Error API
     C*
     C                     CALL 'QPDLOGER'
     C                     PARM           PGMNAM
     C                     PARM EXCPID    MSGID  12
     C                     PARM           MSGKEY  4
     C                     PARM           FAILPT
     C                     PARM 'Y'       JOBLOG  1
     C                     PARM           DATA
     C                     PARM           DATAPT
     C                     PARM           DATA#
     C                     PARM           OBJS
     C                     PARM           OBJS#
     C                     PARM           QUSBN
     C*
     C* If an error on the API call, then indicate a terminal error
     C*
     C           QUSBNC    IFGT 0
     C           'TERM ERR'DSPLY
     C                     END
     C                     ELSE
     C*
     C* If error within *PSSR, then indicate *PSSR error
     C*
     C           '*PSSR   'DSPLY
     C                     END
     C*
     C* No matter how the program got to the *PPSR, end the program
     C*
     C                     MOVE '1'       *INLR
     C                     RETRN
     C                     ENDSR
Related reference
Example in ILE C: Logging software error (OPM API without pointers)