Example in OPM RPG: Registering exit points and adding exit programs

This OPM RPG program registers an exit point with the registration facility. After the successful completion of the registration, the program adds an exit program to the exit point.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

     F***************************************************************
     F***************************************************************
     F*
     F*  Program:      Register an Exit Point
     F*                Add an Exit Program
     F*
     F*  Language:     OPM RPG
     F*
     F*  Description:  This program registers an exit point with the
     F*                registration facility.  After the successful
     F*                completion of the registration of the exit point,
     F*                an exit program is added to the exit point.
     F*
     F*  APIs Used:    QUSRGPT - Register Exit Point
     F*                QUSADDEP - Add Exit Program
     F*
     F***************************************************************
     F***************************************************************
     F*
     FQPRINT  O   F     132            PRINTER                        UC
     E* COMPILE TIME ARRAY
     E                    REC      1000  1
     I*
     I* Keyed Variable Length Record includes
     I*
     I/COPY QSYSINC/QRPGSRC,QUS
     I*
     I* Error Code parameter include.  As this sample program
     I* uses /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* Miscellaneous data
     I*
     IVARREC      DS                           1008
     I                                    B   1   40NBRREC
     I                                        51004 REC
     I I            1                     B100510080VO
     I*
     IOVRLAY      DS
     I                                    B   1   40BINARY
     I                                        1   4 BINC
     I*
     I            DS
     I I            'EXAMPLE_EXIT_POINT  '    1  20 EPNTNM
     I I            'EXAMPLEPGMEXAMPLELIB'   21  40 EPGM
     I I            'EXAMPLE EXIT PROGRAM-   41  65 EPGMDT
     I              ' DATA'
     I I            'EXAMPLE POINT EXAMPL-   66 115 EPTXT
     I              'E'
     I I            25                    B 116 1190EPGMSZ
     C*
     C* Beginning of mainline
     C*
     C* Register the exit point with the registration facility.  If the
     C* registration of the exit point is successful, add an exit
     C* program to the exit point.
     C*
     C* Initialize the error code parameter.  To signal exceptions to
     C* this program by the API, you need to set the bytes provided
     C* field of the error code to zero.  Because this program has
     C* exceptions sent back through the error code parameter, it sets
     C* the bytes provided field to the number of bytes it gives the
     C* API for the parameter.
     C*
     C                     Z-ADD16        QUSBNB
     C*
     C* Set the exit point controls.  Each control field is passed to
     C* the API using a variable length record.  Each record must
     C* start on a 4-byte boundary.
     C*
     C* Set the total number of controls that are being specified on
     C* the call.  This program lets the API take the default for the
     C* controls that are not specified.
     C*
     C                     Z-ADD2         NBRREC
     C*
     C* Set the values for the two controls that are specified:
     C*   Maximum number of exit programs = 10
     C*   Exit point description = 'EXIT POINT EXAMPLE'
     C*
     C                     Z-ADD3         QUSBCC
     C                     Z-ADD4         QUSBCD
     C                     Z-ADD10        BINARY
     C           12        ADD  VO        OF      50
     C                     MOVEABINC      REC,OF
     C                     EXSR CALCVO
     C                     Z-ADD8         QUSBCC
     C                     Z-ADD50        QUSBCD
     C           12        ADD  VO        OF      50
     C                     MOVEAEPTXT     REC,OF
     C                     EXSR CALCVO
     C*
     C* Call the API to register the exit point.
     C*
     C                     CALL 'QUSRGPT'
     C                     PARM           EPNTNM
     C                     PARM 'EXMP0100'FORMAT  8
     C                     PARM           VARREC
     C                     PARM           QUSBN
     C*
     C* If an exception occurs, the API returns the exception in the
     C* error code parameter.  The bytes available field is set to
     C* zero if no exception occurs and greater than zero if an
     C* exception does occur.
     C*
     C           QUSBNC    IFGT 0
     C                     OPEN QPRINT
     C                     EXCPTERREPT
     C                     EXSR DONE
     C                     ENDIF
     C*
     C* If the call to register an exit point is successful, add
     C* an exit program to the exit point.
     C*
     C* Set the total number of exit program attributes that are being
     C* specified on the call.  This program lets the API take the
     C* default for the attributes that are not specified.  Each
     C* attribute record must be 4-byte aligned.
     C*
     C                     Z-ADD2         NBRREC
     C                     Z-ADD1         VO
     C*
     C* Set the values for the two attributes that are being specified:
     C*   Replace exit program    = 1
     C*   Exit program data CCSID = 37
     C*
     C                     Z-ADD4         QUSBCC
     C                     Z-ADD1         QUSBCD
     C           12        ADD  VO        OF      50
     C                     MOVE '1'       REC,OF
     C                     EXSR CALCVO
     C                     Z-ADD3         QUSBCC
     C                     Z-ADD4         QUSBCD
     C                     Z-ADD37        BINARY
     C           12        ADD  VO        OF      50
     C                     MOVEABINC      REC,OF
     C                     EXSR CALCVO
     C*
     C* Call the API to add the exit program.
     C*
     C                     CALL 'QUSADDEP'
     C                     PARM           EPNTNM
     C                     PARM 'EXMP0100'FORMAT
     C                     PARM 1         BINARY
     C                     PARM           EPGM
     C                     PARM           EPGMDT
     C                     PARM           EPGMSZ
     C                     PARM           VARREC
     C                     PARM           QUSBN
     C*
     C* If an exception occurs, the API returns the exception in the
     C* error code parameter.  The bytes available field is set to
     C* zero if no exception occurs and greater than zero if an
     C* exception does occur.
     C*
     C           QUSBNC    IFGT 0
     C                     OPEN QPRINT
     C                     EXCPTERRPGM
     C                     EXSR DONE
     C                     ENDIF
     C                     EXSR DONE
     C*
     C* End of MAINLINE
     C*
     C*
     C* Return to programs caller
     C           DONE      BEGSR
     C                     SETON                     LR
     C                     RETRN
     C                     ENDSR
     C*
     C* Calculate 4-byte aligned offset for next variable length record
     C*
     C           CALCVO    BEGSR
     C           QUSBCD    ADD  12        BINARY
     C                     DIV  4         BINARY
     C                     MVR            BINARY
     C           BINARY    IFEQ 0
     C           QUSBCD    ADD  12        QUSBCB
     C                     ELSE
     C           4         SUB  BINARY    QUSBCB
     C                     ADD  QUSBCD    QUSBCB
     C                     ADD  12        QUSBCB
     C                     END
     C                     MOVEAQUSBC     REC,VO
     C                     ADD  QUSBCB    VO
     C                     ENDSR
     O*
     OQPRINT  E  106           ERREPT
     O                                      'Attempt to register exit'
     O                                      ' point failed: '
     O                         QUSBND
     OQPRINT  E  106           ERRPGM
     O                                      'Attempt to add an exit'
     O                                      ' program failed: '
     O                         QUSBND