Example: Generating and sending an alert

The following ILE RPG program uses both alert APIs.

Note: Read the Code license and disclaimer information for important legal information.
     H
     D***************************************************************
     D***************************************************************
     D*
     D*  Program Name: ALERTS
     D*
     D*  Programming Language: ILE RPG
     D*
     D*  Description:  This program uses alert APIs.  First, it
     D*                calls the Generate Alert (QALGENA) API to
     D*                generate an alert without sending a message
     D*                to QSYSOPR or QHST message queue.  Then it
     D*                uses the Send Alert (QALSNDA) API to send
     D*                the alert to the alert manager.
     D*
     D*  Header Files Included: QUSEC - Error Code Parameter
     D*
     D***************************************************************
     D***************************************************************
     D*
     D* Error Code parameter include
     D*
     D/COPY QSYSINC/QRPGLESRC,QUSEC
     D*
     D*
     D* Miscellaneous data structure
     D*
     DRCVVAR           S            512
     DRCVLEN           S              9B 0 INZ(%SIZE(RCVVAR))
     DALERT_SIZE       S              9B 0
     DMSG_FILE         S             20    INZ('QCPFMSG   QSYS')
     DMSG_ID           S              7    INZ('CPA2601')
     DMSG_DATA         S            100
     DMSG_SIZE         S              9B 0 INZ(0)
     DALERT_TYPE       S              1    INZ('L')
     DORIGIN           S             10    INZ('ALERTS')
     C*
     C* Beginning of mainline
     C*
     C* Set error handling
     C*
     C                   EVAL      QUSBPRV = %SIZE(QUSEC)
     C*
     C* Start by generating an alert for a specific message
     C*
     C                   CALL      'QALGENA'
     C                   PARM                    RCVVAR
     C                   PARM                    RCVLEN
     C                   PARM                    ALERT_SIZE
     C                   PARM                    MSG_FILE
     C                   PARM                    MSG_ID
     C                   PARM                    MSG_DATA
     C                   PARM                    MSG_SIZE
     C                   PARM                    QUSEC
     C*
     C* If no error reported, send the generated alert
     C*
     C     QUSBAVL       IFEQ      0
     C                   CALL      'QALSNDA'
     C                   PARM                    RCVVAR
     C                   PARM                    ALERT_SIZE
     C                   PARM                    ALERT_TYPE
     C                   PARM                    ORIGIN
     C                   PARM                    QUSEC
     C*
     C* If error on send, then display the error message
     C*
     C     QUSBAVL       IFNE      0
     C     QUSEI         DSPLY
     C                   END
     C*
     C* If error on generation, then display the error message
     C*
     C                   ELSE
     C     QUSEI         DSPLY
     C                   END
     C*
     C                   EVAL      *INLR = '1'
     C                   RETURN
     C*
     C* End of MAINLINE
     C*