Starting a watch session

A watch session can be started by the Start Watch (STRWCH) command or by the the Start Watch (QSCSWCH) API.

To start a watch session, follow these steps:
  1. On the command line, enter STRWCH and press F4 (Prompt).
  2. Specify a meaningful session identifier, such as mycleanup, in the Session ID field.
  3. For the Watch program parameter field, specify MYWCHPGM, and type MYLIB for the Watch program Library field. MYWCHPGM is the exit program to be called when the watched-for event occurs.
  4. For the Watch for message, Message identifier field, type CPF0907.
  5. For the Watched message queue, Message queue field, type *SYSOPR. This ensures that your Watch for Event exit program is called when the CPF0907 message is sent to the history log (QHST message queue in library QSYS).
To verify that the watch session was started, follow these steps:
  1. At the command line, type WRKWCH and press F4 (Prompt).
  2. For the Watch field, type *STRWCH.
  3. Check to see that the MYCLEANUP session is listed under the STRWCH type.

After the CPF0907 message is sent to the QHST message queue, the MYWCHPGM program in the MYLIB library is called. This program can call your MYCLNUP program and do any other functions you need by customizing the exit program.

Examples of starting watch sessions

  • Starting a watch on your job
    STRWCH   SSNID(OWN_JOB) WCHPGM(MYLIB/MYPGM)          
    WCHMSG((CPF0001)) WCHMSGQ((*JOBLOG)) 

    This command starts the watch session named OWN_JOB, watching for the CPF0001 message to occur on the job that called the STRWCH command. When the CPF0001 message is sent to the current job log, the MYPGM program in the MYLIB library is called to be notified of the event.

  • Starting a watch for a message specifying a Run Priority
    STRWCH   SSNID(*GEN) WCHPGM(MYLIB/EXTPGM)          
    WCHMSG((CPF1804))         
    WCHMSGQ((*SYSOPR) (*JOBLOG))          
    WCHJOB((*ALL/MYUSER/MYJOBNAME))          
    RUNPTY(10)

    This command starts a watch session to call the MYLIB/EXTPGM exit program when the CPF1804 message is found on the system operator message queue or within the *ALL/MYUSER/MYJOBNAME job log. A unique watch session identifier is generated. The session identifier is returned to the message data of the CPC3901 completion message that is sent after the watch session starts successfully. The job by which the exit program will be called is run with a run priority of 10.

  • Starting a watch for a message specifying Comparison Data
    STRWCH   SSNID(FRMPGM) WCHPGM(MYLIB/EXTPGM)         
    WCHMSG((CPC3922 QSCSWCH *FROMPGM))    
    WCHMSGQ((*HSTLOG))

    This command starts a watch session to call the MYLIB/EXTPGM exit program when the QSCSWCH program sends the CPC3922 message to the message queue QHST in library QSYS.

  • Starting a watch for a Licensed Internal Code log entry
    STRWCH   SSNID(LICLOGSSN) WCHPGM(*LIBL/EXTPGM)         
    WCHLICLOG(('99??' 9932 MYJOBNAME))

    This command starts LICLOGSSN to watch for a Licensed Internal Code log entry that has a major code starting with 99 and a minor code of 9932 generated on the system. Also, the Licensed Internal Code log information needs to contain the text MYJOBNAME. The first match of the EXTPGM program found in the library list will be called, which notifies you that the event occurred.

  • Starting a watch for a PAL entry and Call Exit Program at start and end times
    STRWCH   SSNID(PALSSN)          
    WCHPGM(USRLIB/USRPGM) 
    CALLWCHPGM(*STRWCH *ENDWCH)
    WCHPAL((B600512? MYRSC *RSCNAME))   

    This command starts PALSSN to watch for a Product Activity Log (PAL) entry that has a system reference code starting with B600512 generated on the system. Also, the PAL resource name contains the text MYRSC. The program USRLIB/USRPGM is called, which notifies you that the event occurred. It is also called before you start watching for any event and when the watch session is ending.