25
Mon, Nov
1 New Articles

The Check Power Off Schedule (CHKPWRSCD) Utility

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

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: