Example: Power-handling CL program
The sample power-handling CL program can help you build your own program according to your specific system requirements.
Although this example CL program should work correctly as written, you need adjust it for your specific system requirements. For example, add additional recovery to the program by monitoring for error conditions specific to your system. You also need to supply a user-written program that performs the steps necessary to prepare for a normal shutdown of the system. These steps might include holding job queues, sending messages, and ending subsystems. The program should restart normal operations if the power outage ends before the system is turned off.
The program performs the following actions:
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
SEQNBR*...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...
1.00 PGM
2.00 DCL VAR(&UPSMSGQ) TYPE(*CHAR) LEN(20)
3.00 DCL VAR(&LIB) TYPE(*CHAR) LEN(20)
4.00 DCL VAR(&MSGQ) TYPE(*CHAR) LEN(20)
5.00 DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
6.00 DCL VAR(&ENDSTS) TYPE(*CHAR) LEN(1)
7.00 DCL VAR(&WAIT) TYPE(*DEC) LEN(6)
8.00 DCL VAR(&HOUR) TYPE(*DEC) LEN(6)
9.00 DCL VAR(&MIN) TYPE(*DEC) LEN(6)
10.00 DCL VAR(&SEC) TYPE(*DEC) LEN(6)
11.00 DCL VAR(&TIME) TYPE(*CHAR) LEN(6)
12.00 DCL VAR(&START) TYPE(*DEC) LEN(6)
13.00 DCL VAR(&END) TYPE(*DEC) LEN(6)
14.00 DCL VAR(&RESULT) TYPE(*DEC) LEN(6)
15.00 DCL VAR(&PGM) TYPE(*CHAR) LEN(10)
16.00 RTVSYSVAL SYSVAL(QUPSMSGQ) RTNVAR(&UPSMSGQ)
17.00 CHGVAR VAR(&MSGQ) VALUE(%SST(&UPSMSGQ 1 10))
18.00 CHGVAR VAR(&LIB) VALUE(%SST(&UPSMSGQ 11 10))
19.00 DLTMSGQ MSGQ(&LIB/&MSGQ)
20.00 MONMSG MSGID('CPF2105') /* Message queue not found. */
21.00 CRTMSGQ MSGQ(&LIB/&MSGQ) TEXT('UPS Power handling +
22.00 program message queue') AUT(*EXCLUDE)
23.00 ALCOBJ OBJ((&LIB/&MSGQ *MSGQ *EXCL))
24.00
25.00 A: RCVMSG MSGQ(&LIB/&MSGQ) WAIT(600) RMV(*YES) +
26.00 MSGID(&MSGID)
27.00 IF COND(&MSGID *NE CPF1816) THEN(DO)
28.00 RTVJOBA ENDSTS(&ENDSTS)
29.00 IF COND(&ENDSTS *EQ '1') THEN(GOTO CMDLBL(ENDPGM))
30.00 GOTO CMDLBL(A)
31.00 ENDDO
32.00
33.00 /* Check to see if this is a short power outage. */
34.00 IF COND(&MSGID *EQ 'CPF1816') THEN(DO)
35.00 RCVMSG MSGQ(&LIB/&MSGQ) WAIT(10) RMV(*YES) +
36.00 MSGID(&MSGID) /* Wait ten seconds)
37.00 IF COND(&MSGID *EQ 'CPF1817') THEN(GOTO CMDLBL(A))
38.00 ENDDO
39.00
40.00 /* Power outage was longer than 10 seconds. */
41.00 CALL PGM(&LIB/&PGM) /* User program that prepares +
42.00 system for possible shutdown. */
43.00
44.00 /* Check to see if this is a long power outage. */
45.00 CHGVAR VAR(&WAIT) VALUE(01200) /* 20 minutes. */
46.00 B: RTVSYSVAL SYSVAL(QTIME) RTNVAR(&TIME)
47.00 CHGVAR VAR(&HOUR) VALUE(%SST(&TIME 1 2))
48.00 CHGVAR VAR(&MIN) VALUE(%SST(&TIME 3 2))
49.00 CHGVAR VAR(&SEC) VALUE(%SST(&TIME 5 2))
50.00 CHGVAR VAR(&START) VALUE((&SEC) + (&MIN * 60) + +
51.00 (&HOUR * 3600))
52.00 RCVMSG MSGQ(&LIB/&MSGQ) WAIT(&WAIT) RMV(*YES) +
53.00 MSGID(&MSGID)
54.00 IF COND(&MSGID *EQ 'CPF1817') THEN(DO)
55.00 CALL PGM(&LIB/&PGM) /* User program that restarts +
56.00 system operations. */
57.00 GOTO CMDLBL(A)
58.00 ENDDO
59.00
60.00 IF COND(&MSGID *NE 'CPF1817') THEN(DO)
61.00 RTVSYSVAL SYSVAL(QTIME) RTNVAR(&TIME)
62.00 CHGVAR VAR(&HOUR) VALUE(%SST(&TIME 1 2))
63.00 CHGVAR VAR(&MIN) VALUE(%SST(&TIME 3 2))
64.00 CHGVAR VAR(&SEC) VALUE(%SST(&TIME 5 2))
65.00 CHGVAR VAR(&END) VALUE((&SEC) + (&MIN * 60) + +
66.00 (&HOUR * 3600))
67.00 CHGVAR VAR(&RESULT) VALUE(&END - &START)
68.00 IF COND(&RESULT < 0) THEN(CHGVAR VAR(&RESULT) +
69.00 VALUE(86400 + &RESULT)) /* Check for +
70.00 change of day. 86400 = 24 hours. */
71.00 IF COND(&RESULT *GE &WAIT) THEN(PWRDWNSYS +
72.00 OPTION(*IMMED) /* uninterruptible power supply +
battery reserve has expired. */
74.00
75.00 CHGVAR VAR(&WAIT) VALUE(&WAIT - &RESULT) /* UPS +
76.00 battery reserve has not expired. */
77.00 GOTO CMDLBL(B)
78.00 ENDDO
79.00
80.00 ENDPGM: DLCOBJ OBJ((&LIB/&MSGQ *MSGQ *EXCL))
81.00 ENDPGM