Scenario: Use the watch for event function with an exit program

To learn how to use the watch for event function with an exit program, read this scenario.

Start of changeYou have a MYCLNUP program that you run whenever you want to free up storage space on your system. You usually run this program when message CPF0907 (Serious storage condition might exist) is sent to the system operator message queue (QSYSOPR).End of change

You use the watch for event function to automatically run your clean up program when the amount of available storage in the system auxiliary storage pool has reached the threshold value. Your user exit program also performs some special actions when the available storage is less than 5 percent.

Start of changeTo run MYCLNUP when message CPF0907 enters the specified message queue, follow these steps:End of change

Start of change
  1. Start a watch session:
    1. At the command line, type STRWCH and press F4.
    2. For the Session ID prompt, specify a meaningful session identifier, such as mycleanup.
    3. For the Watch program parameter, specify MYWCHPGM, and type MYLIB for the Watch program Library prompt. MYWCHPGM is the exit program to be called when the watched for event occurs. See Exit program for watch for event scenario.
    4. For the Watch for message, Message identifier prompt, type CPF0907.
    5. For the Watched message queue, Message queue prompt, type *SYSOPR. This ensures that your watch exit program is called when the CPF0907 message is sent to the system operator message queue.
  2. Verify that the watch session started:
    1. At the command line, type WRKWCH and press F4.
    2. For the Watch prompt, type *STRWCH.
    3. Check to see that the MYCLEANUP session is listed under the STRWCH type.

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

  3. When you do not need your watch session anymore, end it:
    1. At the command line, type ENDWCH and press F4.
    2. For the Session ID prompt, specify mycleanup.
  4. Verify that the watch session ended:
    1. At the command line, type WRKWCH and press F4.
    2. For the Watch prompt, type *STRWCH.
    3. Check to see that the MYCLEANUP session is not listed anymore.
      Note: You can also type DSPMSG MSGQ(*SYSOPR) to verify that the watch session has ended. You should see the CPI3999 message, which indicates that the MYCLEANUP watch session was ended because of reason code 08. Reason code 08 indicates that the End Watch (ENDWCH) command or End Watch (QSCEWCH) API was issued.
End of change