The Check Power Off Schedule (CHKPWRSCD) Utility

IT Infrastructure - Other
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Brief: Loss of power can short-circuit the best of applications, but it can be really frustrating if someone simply forgot to change the power on/off schedule.

The power on/off schedule is one of the many great features added to the AS/400 operating system in recent years, but you probably won't think so if a scheduled automatic power off ever cancels one of your critical applications.

Changing the power on/off schedule to accommodate applications that may be active at the time a power off is scheduled is a very easy thing to forget. The purpose of making functions like this automatic is so we don't have to think about them. The problem with this, of course, is sometimes we do need to think about them. That is where the handy little utility presented here comes in.

The Check Power Off Schedule (CHKPWRSCD) command will allow you to build a reminder into your longer-running, mission-critical applications so users on your system won't forget to change the power off schedule.

Why Would I Need It?

Let's establish a fictitious scenario to illustrate how this utility may come in handy. Your monthly close procedure takes six hours to run. Your AS/400 is scheduled to shut down at 11:30 p.m. Normally, the close is not a problem, because all departments know they have to be off the system at 4:30 p.m. on the day the month is closed. The monthly close is started promptly at 5 p.m. once the system backup is complete. This month, however, the operator is out with a cold. The backup operator knows he has to run the month-end close, but does not begin the procedure until 8 p.m. because he's a little behind. At 11:30 p.m., the system powers off as scheduled, and the monthly close does not complete. At 5:15 a.m. you get a phone call from the morning operator. The order entry programs will not run.

The purpose of the utility presented in this article is simple. It checks the power off schedule, compares it to the estimated completion time of the job and issues a warning if there is not enough time for the job to finish. You can embed this utility in the beginning of any of your longer-running programs and it will serve as an early warning system for potential disaster.

How Does It Work?

The CHKPWRSCD command (see 1) passes the estimated number of hours required to complete the job to the command processing program, PWR001RG (see 2). PWR001RG then calculates the job ending date and time. PWR001RG calls CL program PWR001CL (see 3) for each date within the estimated job duration to determine if a power off has been scheduled within the calculated time frame. If the number of hours (maximum of 99) specified carries the job over to future dates, the program will check the power off schedule of the subsequent dates accordingly.

The CHKPWRSCD command (see Figure 1) passes the estimated number of hours required to complete the job to the command processing program, PWR001RG (see Figure 2). PWR001RG then calculates the job ending date and time. PWR001RG calls CL program PWR001CL (see Figure 3) for each date within the estimated job duration to determine if a power off has been scheduled within the calculated time frame. If the number of hours (maximum of 99) specified carries the job over to future dates, the program will check the power off schedule of the subsequent dates accordingly.

PWR001CL determines this by calling the Retrieve Power Schedule Entry (RTVPWRSCDE) command. The input to the RTVPWRSCDE command is a date (&OFFDATE). If a power off is scheduled for &OFFDATE, the output from RTVPWRSCDE is the power off time (&OFFTIME).

If program PWR001RG determines the power off schedule falls within the estimated program duration, it displays a warning screen through display file PWR001DF (see 4). A message (illustrated in 5) is displayed advising the operator that the power off schedule should be changed. The operator can press F3 to cancel, which places the literal "CANCEL" in the RTNCOD parameter. If the operator presses F13 to ignore the warning, the literal "OVRRDE" is placed in the RTNCOD parameter. When there is no conflict with the power off schedule, the RTNCOD parameter will contain the literal "OK".

If program PWR001RG determines the power off schedule falls within the estimated program duration, it displays a warning screen through display file PWR001DF (see Figure 4). A message (illustrated in Figure 5) is displayed advising the operator that the power off schedule should be changed. The operator can press F3 to cancel, which places the literal "CANCEL" in the RTNCOD parameter. If the operator presses F13 to ignore the warning, the literal "OVRRDE" is placed in the RTNCOD parameter. When there is no conflict with the power off schedule, the RTNCOD parameter will contain the literal "OK".

6 contains a sample CL program (TSTPWRCHK) that illustrates how to use the CHKPWRSCD command and also allows you to test it. To run the test program, call it and pass the number of hours you estimate a job needs to complete. Specify the number of hours as a character value enclosed in single quotes. For example, if you think a job will need three hours to complete, pass the literal '03' in paramter one. If the power off schedule is set to shut down the system within three hours, a warning message similar to the one illustrated in 5 will be displayed.

Figure 6 contains a sample CL program (TSTPWRCHK) that illustrates how to use the CHKPWRSCD command and also allows you to test it. To run the test program, call it and pass the number of hours you estimate a job needs to complete. Specify the number of hours as a character value enclosed in single quotes. For example, if you think a job will need three hours to complete, pass the literal '03' in paramter one. If the power off schedule is set to shut down the system within three hours, a warning message similar to the one illustrated in Figure 5 will be displayed.

Not Just for Interactive Jobs

The example usage of the CHKPWRSCD command in this article is for procedures that begin with an interactive program. When the error condition is encountered, a warning display indicating the problem is sent to the requesting terminal. This program could be adjusted to send a message to the message queue of the end user or system operator instead. If you wish to get fancy, the Retrieve Job Attributes (RTVJOBA) command could be used to retrieve the job type (RTVJOBA parameter TYPE) and determine whether the job was running in an interactive (job type '1') or batch (job type '0') environment and act upon it accordingly. There are two limitations in this utility of which you should be aware:

1. It assumes a date format of MDY. 2. It doesn't handle leap years.

No Apologies Accepted

Employing this utility program may save you from getting that rude early call from the morning operator. You really shouldn't have to endure anything like that until after you've had that first cup of coffee.

Doug Pence is the founder and Ron Hawkins is the research and development manager of Computer Processing Unlimited, Inc. in San Diego, California.


The Check Power Off Schedule (CHKPWRSCD) Utility

Figure 1 The CHKPWRSCD Command

 /*==================================================================*/ /* To compile: */ /* */ /* CRTCMD CMD(XXX/CHKPWRSCD) PGM(XXX/PWR001RG) + */ /* SRCFILE(XXX/QCMDSRC) ALLOW(*BPGM *IPGM + */ /* *BREXX *IREXX) */ /* */ /*==================================================================*/ CHKPWRSCD: CMD PROMPT('Check Power Off Schedule') PARM KWD(RTNCOD) TYPE(*CHAR) LEN(6) RTNVAL(*YES) + PROMPT('Return Code:') PARM KWD(HOURS) TYPE(*DEC) LEN(2 0) + PROMPT('Number of hours to + Check for:') 
The Check Power Off Schedule (CHKPWRSCD) Utility

Figure 2 RPG Command Processing Program PWR001RG

 *=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/PWR001RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FPWR001DFCF E WORKSTN * E MAX 12 12 2 0 * I DS I 1 20YY I 3 40MM I 5 60DD I 3 60MMDD ** C *ENTRY PLIST C PARM RTNCOD 6 C PARM HOURS 20 * C MOVEL'OK' RTNCOD P C TIME UTIME 60 C MOVELUTIME UHHMM 40 C HOURS MULT 100 TEST 50 C ADD UHHMM TEST C Z-ADD1 DAYS 20 C TEST DOWGT2400 C ADD 1 DAYS C SUB 2400 TEST C ENDDO * C MOVE UYEAR YY C MOVE UMONTH MM C MOVE UDAY DD * C DO DAYS C ADD 1 CURDAY 20 C MOVELMMDD PWRDAT C MOVE YY PWRDAT C CALL 'PWR001CL' C PARM PWROFF 6 C PARM PWRDAT 6 C PWROFF IFEQ '*NONE' C EXSR INCDAT C ITER C ENDIF C MOVELPWROFF HHMM 40 C MOVELUDATE TODAY 6 C TODAY IFEQ PWRDAT C HHMM ANDLTUHHMM C ITER C ENDIF C DAYS IFEQ CURDAY C TEST IFGT HHMM C MOVE *ON WARNEM 1 C ENDIF C LEAVE C ENDIF C MOVE *ON WARNEM C LEAVE C ENDDO * C WARNEM IFEQ *ON C HHMM IFGE 1200 C MOVE 'PM' OFFAMP 2 C ELSE C MOVE 'AM' OFFAMP C END C HHMM IFGE 1300 C SUB 1200 HHMM C END C HHMM IFLT 0100 C ADD 1200 HHMM C END C MOVELHHMM WORK2A 2 C WORK2A CAT ':':0 OFFTIM C MOVE HHMM WORK2A C OFFTIM CAT WORK2A:0 OFFTIM C OFFTIM CAT OFFAMP:0 OFFTIM C MOVE PWRDAT OFFDAT * C *INKC DOUEQ*ON C *INKM OREQ *ON C EXFMTWARNING C ENDDO C *INKC IFEQ *ON C MOVE 'CANCEL' RTNCOD C ELSE C *INKM IFEQ *ON C MOVE 'OVRRDE' RTNCOD C ENDIF C ENDIF C ENDIF C MOVE *ON *INLR *================================================================ C INCDAT BEGSR *================================================================ C ADD 1 DD C MOVE MAX,MM MMAX 20 C YY DIV 4 CHKLY 20 C MVR REM 10 C MM IFEQ 02 C REM ANDEQ*ZEROS C ADD 1 MMAX C END C DD IFGT MMAX C Z-ADD1 DD C ADD 1 MM C END C MM IFGT 12 C Z-ADD1 MM C ADD 1 YY C END C ENDSR *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ** MAXIMUM # OF DAYS PER EACH MONTH 312831303130313130313031 
The Check Power Off Schedule (CHKPWRSCD) Utility

Figure 3 CL Program PWR001CL

 /*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/PWR001CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ PWR001CL: PGM PARM(&OFFTIME &OFFDATE) DCL VAR(&OFFTIME) TYPE(*CHAR) LEN(6) DCL VAR(&OFFDATE) TYPE(*CHAR) LEN(6) RTVPWRSCDE DAY(&OFFDATE) PWROFFTIME(&OFFTIME) ENDPGM: ENDPGM 
The Check Power Off Schedule (CHKPWRSCD) Utility

Figure 4 Display File PWR001DF

 *=============================================================== * To compile: * * CRTDSPF FILE(XXX/PWR001DF) SRCFILE(XXX/QDDSSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A DSPSIZ(24 80 *DS3) A CA03 A CA13 A R WARNING A 1 27'Power Off Schedule Conflict' A DSPATR(HI) A 3 11'Current date is' A 3 27DATE EDTCDE(Y) DSPATR(HI) A 5 11'Current time is' A 5 27TIME DSPATR(HI) A 7 11'The job you are attempting to run - A requires' A HOURS 2Y 0O 7 54DSPATR(HI) A 7 57'hours to run.' A 9 11'WARNING!' A DSPATR(HI) A DSPATR(BL) A 11 11'Your system is currently scheduled- A to shut down at' A OFFTIM 8A O 11 62DSPATR(HI) A 12 11'on' A OFFDAT 6Y 0O 12 14DSPATR(HI) EDTCDE(Y) A 12 23'.' A 12 26'You should change your power off s- A chedule' A 13 11'before proceeding with this proced- A ure.' A 15 11'If you want to continue at your ow- A n risk, you may ignore' A 16 11'the warning by pressing F13.' A 23 2'F3=Exit' COLOR(BLU) A 23 13'F13=Ignore' COLOR(BLU) *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 
The Check Power Off Schedule (CHKPWRSCD) Utility

Figure 5 Warning Message Display

 UNABLE TO REPRODUCE GRAPHICS 
The Check Power Off Schedule (CHKPWRSCD) Utility

Figure 6 CL Program TSTPWRCHK (Tests the CHKPWRSCD Command)

 /*==================================================================*/ /* Test Check Power Off Schedule (CHKPWRSCD) command */ /*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/TSTPWRCHK) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ TSTPWRCHK: PGM PARM(&CHRTIM) DCL VAR(&RTNCOD) TYPE(*CHAR) LEN(6) DCL VAR(&CHRTIM) TYPE(*CHAR) LEN(2) DCL VAR(&ESTTIM) TYPE(*DEC) LEN(2 0) CHGVAR VAR(&ESTTIM) VALUE(&CHRTIM) CHKPWRSCD RTNCOD(&RTNCOD) HOURS(&ESTTIM) IF COND(&RTNCOD *EQ 'OK') THEN(GOTO + CMDLBL(START)) ELSE CMD(IF COND(&RTNCOD *EQ 'CANCEL') THEN(GOTO + CMDLBL(ENDPGM))) ELSE CMD(IF COND(&RTNCOD *EQ 'OVRRDE') + THEN(SNDPGMMSG MSGID(CPF9898) + MSGF(QCPFMSG) MSGDTA('You have chosen to + override the warning that there may not + be enough time to run this job') + MSGTYPE(*COMP))) START: /* Job commands would go here */ ENDPGM: ENDPGM 
BLOG COMMENTS POWERED BY DISQUS