Scenario: Using the watch for event function with an exit program
This scenario explains how to use the watch for event function with an exit program.
You 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).
You use the watch for event function to automatically run your cleanup 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 five percent.
When message CPF0907 enters the specified message queue, follow these steps to run MYCLNUP:
- Start a watch session:
- At the command line, type STRWCH and press F4 (Prompt).
- For the Session ID prompt, specify a meaningful session identifier, such as mycleanup.
- 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.
- For the Watch for message, Message identifier prompt, type CPF0907.
- For the Watched message queue, Message queue prompt, type *SYSOPR. This ensures that your Watch for Event exit program is called when the CPF0907 message is sent to the system operator message queue.
- Verify that the watch session started:
- At the command line, type WRKWCH and press F4.
- For the Watch prompt, type *STRWCH.
- 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.
- When you do not need your watch session anymore, end it:
- At the command line, type ENDWCH and press F4.
- For the Session ID prompt, specify mycleanup.
- Verify that the watch session ended:
- At the command line, type WRKWCH and press F4.
- For the Watch prompt, type *STRWCH.
- Check to see that the MYCLEANUP session is not listed anymore.
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.
Parent topic:
Watch for event functionRelated reference
Scenario: Exit program for Watch for Event