Example: Watch exit program

This is sample code for a watch trace exit program. It is written in control language (CL).

Use this exit program as a starting point to help you create your own watch trace program. You can modify the code to allow the program to perform additional function. Find out how you can extend the capability of the watch function using the watch exit program example.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
   /*********************************************************/
   /* THIS IS A SAMPLE CODE FOR WATCH FOR TRACE EVENT       */
   /* FACILITY                                              */
   /*                                                       */
   /* FUNCTION: WHEN THE TRACE OPTION SETTING PARAMETER     */
   /* INDICATES THAT A MESSAGE ID MATCHED WITH THE ONE BEING*/
   /* WATCHED, THIS PROGRAM WILL PRINT THE HISTORY LOG AND  */
   /* STOP THE TRACE COMMAND EXECUTION. OTHERWISE, THIS     */
   /* WILL INDICATE TO CONTINUE WITH THE EXECUTION.         */
   /*                                                       */
   /* NOTE: MYLIB/MYOBJECT IS A DATA AREA THAT IS           */
   /*   CONTINUOUSLY CHANGING DURING THE PROCESS. THE USER  */
   /*   WANTS TO DUMP IT PERIODICALLY TO CHECK HOW ITS      */
   /*   CONTENT IS CHANGING AND WHAT IS THE FINAL VALUE     */
   /*   WHEN THE WATCHED MESSAGE OCCURS. THIS DATA AREA     */
   /*   WILL BE DUMPED AT THE BEGINNING (*ON), WHEN THE     */
   /*   INTERVAL TIME ELAPSES (*INTVAL), AND WHEN THE       */
   /*   WATCHED MESSAGE OCCURS (*MSGID)                     */
   /*                                                       */
   /* THE FOLLOWING IS AN EXAMPLE OF THE WATCH FOR TRACE    */
   /* EVENTS PARAMETERS, AS THEY WOULD BE SPECIFIED FOR A   */
   /* TRACE COMMAND ISSUING THE CURRENT SAMPLE CODE:        */
   /*                                                       */
   /* WCHMSG((CPF0001)) TRCPGM(MYLIB/WCHEXTP) TRCPGMITV(30) */
   /*********************************************************/
   PGM PARM(&TRCOPTSET &RESERVED &OUTPUT &COMPDATA)
             DCL        VAR(&TRCOPTSET) TYPE(*CHAR) LEN(10) /* +
                          Reason why the program was called */
             DCL        VAR(&RESERVED) TYPE(*CHAR) LEN(10) /* This +
                          parameter is only used of TRCTCPAPP +
                          command and it is not relevant for Watch +
                          for Trace Event Facility */
             DCL        VAR(&OUTPUT) TYPE(*CHAR) LEN(10) /* +
                          Indicates if watch facility should stop +
                          or continue running */
             DCL        VAR(&COMPDATA) TYPE(*CHAR) LEN(92) /* Not +
                          needed for this sample */
   /*********************************************************/
   /*              BEGIN OF PROGRAM PROCESSING              */
   /*********************************************************/
      IF         COND(&TRCOPTSET *EQ '*ON       ') THEN(DO) +
                          /* If the program was called at the +
                          beginning of the processing.          */
               /*  This section is usually used to set up +
                   the environment before the trace starts */
             DMPOBJ     OBJ(MYLIB/MYOBJECT) OBJTYPE(*DTAARA) /* Dump +
                          Object for problem determination */
             CHGVAR     VAR(&OUTPUT) VALUE('*CONTINUE ') /* Let the +
                          trace to continue running */
      ENDDO      /* End if *ON */
      ELSE       CMD(IF COND(&TRCOPTSET *EQ '*MSGID    ') +
                          THEN(DO)) /* If the message id matched */
             DSPLOG     LOG(QHST) OUTPUT(*PRTSECLVL) /* Print the +
                          History Log */
             DMPOBJ     OBJ(MYLIB/MYOBJECT) OBJTYPE(*DTAARA) /* Dump +
                          object for problem determination */
             CHGVAR     VAR(&OUTPUT) VALUE('*STOP     ') /* +
                          Indicates Watch Facility to Stop */
      ENDDO      /* End if *MSGID */
      ELSE       CMD(IF COND(&TRCOPTSET *EQ '*INTVAL   ') +
                          THEN(DO)) /* If the exit program was +
                          called because the interval +
                          elapsed                                  */
               /*  This section is usually used to perform +
                   tasks periodically. Like dumping objects, +
                   checking conditions and optionally end +
                   the watch facility      */
             DMPOBJ     OBJ(MYLIB/MYOBJECT) OBJTYPE(*DTAARA) /* Dump +
                          object for problem determination */
             CHGVAR     VAR(&OUTPUT) VALUE('*CONTINUE ') /* Let the +
                          trace and the watch facility to continue +
                          running */
      ENDDO      /* End if *INTVAL */
      ELSE       CMD(CHGVAR VAR(&OUTPUT) VALUE('*CONTINUE ')) +
                          /* Otherwise, watch facility will +
                          continue running */
   ENDPGM
Related reference
Extend the watch function using the watch exit program example