02
Sat, Nov
2 New Articles

TechTalk: Don't Get Stood Up

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

An old melody's lyrics say, "if it takes forever, I will wait for you." You may be willing to wait forever for another person, but having to do so for an AS/400 object is a bit too much. And that sort of thing is common enough in CL programming.

For example, suppose you have two batch jobs running in parallel. One of them calls a program that creates a summary file, which must be used by the other job. You don't want to schedule both jobs into a single-threaded job queue because there are portions of each job that can run at the same time without trouble, and you would save time by doing so.

Obviously, the second job must wait for the first one to create the file. You then have to code a loop in your CL program, checking for the existence of the summary file and, if it doesn't exist, delaying the job (DLYJOB command) for a short time before testing again.

Or consider having to wait for a data area to become available (it was allocated to another job). Again, you'd have to try to allocate it and, if it fails, delay the job and try again. It seems like this chore is common enough to deserve a simpler solution.

This problem can be solved with the Wait For Object command (WAITOBJ), which is shown in Figures 1a and 1b. When you include WAITOBJ in a CL program, the CL program will effectively wait until the condition you specify is satisfied, up to a maximum time that you also specify. If this maximum time is reached without satisfying the wait condition, WAITOBJ ends with an escape message CPF0002 which you can trap in your CL program with a MONMSG.

Parameter FOR determines what to wait for: the existence of an object (*EXIST), the nonexistence of an object (*NONEXIST), or the availability to allocate an object (*ALLOC).

Parameter OBJ and OBJTYPE define the object to wait for. Parameter MBR is required only if OBJTYPE(*FILE) is specified, and it refines the wait condition to a specific file member.

Parameter ALLOC is required only if FOR(*ALLOC) is specified. You use it to indicate what allocation you need to obtain for the object.

Parameter MAXNBRTRY indicates how many times the system will check for the object existence (or nonexistence, or availability to allocate it); you can enter a number between 1 and 86400, or *NOMAX. Parameter TRYWAIT indicates how many seconds to wait between attempts.

Suppose, that your CL program needs to wait for object MYLIB/MYFILE (type *FILE) to become available, since you have to allocate it exclusively. Code the following in your CL program:

 WAITFILE FOR(*ALLOC) + OBJ(MYLIB/MYFILE) + OBJTYPE(*FILE) MBR(*FIRST) ALLOC(*EXCL) MAXNBRTRY(15) TRYWAIT(60) 

Coded this way, the CL program will try a maximum of 15 times to allocate the file exclusively. Each time it fails, it will wait 60 seconds. If the allocation is unsuccessful after the total time (15 minutes), escape message CPF0002 will be returned to your CL program. Your CL program can then determine what to do in that case.

Besides entering the source and compiling, WAITOBJ requires the existence of a message file with at least two messages. The command definition's DEP statements make reference to messages OBJ0001 and OBJ0002. When the command is created, the MSGF parameter references message file WAITOBJ. If you already have a message file you can use it. You may have to change the message IDs to something else.

If you don't have a suitable message file, create it by executing the commands listed in 1c.

If you don't have a suitable message file, create it by executing the commands listed in Figure 1c.


TechTalk: Don't Get Stood Up

Figure 1A Command WAITOBJ

 WAITOBJ: CMD PROMPT('Wait for Object') PARM KWD(FOR) TYPE(*CHAR) LEN(9) RSTD(*YES) + VALUES(*EXIST *NONEXIST *ALLOC) MIN(1) + PROMPT('Wait for') PARM KWD(OBJ) TYPE(Q1) MIN(1) PROMPT('Object name') PARM KWD(OBJTYPE) TYPE(*CHAR) LEN(8) RSTD(*YES) + VALUES(*ALRTBL *AUTL *CFGL *CHTFMT *CLD + *CLS *CMD *COSD *CSPMAP *CSPTBL *CTLD + *DEVD *DOC *DTAARA *DTADCT *DTAQ *EDTD + *FCT *FILE *FLR *FNTRSC *FORMDF *GSS + *JOBD *JOBQ *JRN *JRNRCV *LIB *LIND *MENU + *MODD *MSGF *MSGQ *OUTQ *OVL *PAGSEG *PDG + *PGM *PNLGRP *PRDAVL *PRDDFN *PRDLOD + *QMFORM *QMQRY *QRYDFN *RCT *SBSD *SCHIDX + *SPADCT *SSND *S36 *TBL *USRIDX *USRPRF + *USRQ *USRSPC) MIN(1) PROMPT('Object type') PARM KWD(MBR) TYPE(*NAME) LEN(10) SPCVAL((*NONE) + (*FIRST) (*LAST)) PROMPT('Member name, if + *FILE') PARM KWD(ALLOC) TYPE(*CHAR) LEN(7) RSTD(*YES) + VALUES(*SHRRD *SHRNUP *SHRUPD *EXCLRD + *EXCL) PROMPT('Desired lock state') PARM KWD(MAXNBRTRY) TYPE(*DEC) LEN(5 0) DFT(60) + RANGE(1 86400) SPCVAL((*NOMAX 99999)) + PROMPT('Maximum number of tries') PARM KWD(TRYWAIT) TYPE(*DEC) LEN(5 0) DFT(60) + RANGE(1 3600) PROMPT('Wait seconds + between tries') Q1: QUAL TYPE(*NAME) LEN(10) MIN(1) QUAL TYPE(*NAME) LEN(10) DFT(*LIBL) + SPCVAL((*LIBL) (*CURLIB)) PROMPT('Library') DEP CTL(&OBJTYPE *EQ *FILE) PARM((MBR)) + MSGID(OBJ0001) DEP CTL(&FOR *EQ *ALLOC) PARM((ALLOC)) + MSGID(OBJ0002) 
TechTalk: Don't Get Stood Up

Figure 1B CL program OBJ008CL

 OBJ008CL: + PGM PARM(&FOR &QUALOBJ &OBJTYPE &MBR &ALLOC &MAXNBRTRY &TRYWAIT) DCL VAR(&ALLOC) TYPE(*CHAR) LEN(7) DCL VAR(&FOR) TYPE(*CHAR) LEN(9) DCL VAR(&MAXNBRTRY) TYPE(*DEC) LEN(5 0) DCL VAR(&MAXTIME) TYPE(*DEC) LEN(10 0) DCL VAR(&MBR) TYPE(*CHAR) LEN(10) DCL VAR(&OBJ) TYPE(*CHAR) LEN(10) DCL VAR(&OBJLIB) TYPE(*CHAR) LEN(10) DCL VAR(&OBJTYPE) TYPE(*CHAR) LEN(8) DCL VAR(&QUALOBJ) TYPE(*CHAR) LEN(20) DCL VAR(&TIMEWAITED) TYPE(*DEC) LEN(10 0) DCL VAR(&TRYWAIT) TYPE(*DEC) LEN(5 0) IF COND(&MBR *EQ ' ' *AND &FOR *NE '*ALLOC') THEN(CHGVAR + VAR(&MBR) VALUE(*NONE)) /* Break qualified name */ CHGVAR VAR(&OBJ) VALUE(%SST(&QUALOBJ 1 10)) CHGVAR VAR(&OBJLIB) VALUE(%SST(&QUALOBJ 11 10)) /* Determine how much time to wait in total */ IF COND(&MAXNBRTRY *LT 99999) THEN(DO) CHGVAR VAR(&MAXTIME) VALUE(&TRYWAIT * &MAXNBRTRY) CHGVAR VAR(&TIMEWAITED) VALUE(0) ENDDO /* Loop until condition satisfied or time expires */ /* Check for object existence */ LOOP: + IF COND(&FOR *EQ '*EXIST') THEN(DO) CHKOBJ OBJ(&OBJLIB/&OBJ) OBJTYPE(&OBJTYPE) MBR(&MBR) MONMSG MSGID(CPF9801 CPF9810 CPF9815) EXEC(GOTO CMDLBL(WAIT)) GOTO CMDLBL(ENDPGM) ENDDO /* Check for object nonexistence */ IF COND(&FOR *EQ '*NONEXIST') THEN(DO) CHKOBJ OBJ(&OBJLIB/&OBJ) OBJTYPE(&OBJTYPE) MBR(&MBR) MONMSG MSGID(CPF9801 CPF9810 CPF9815) EXEC(GOTO CMDLBL(ENDPGM)) GOTO CMDLBL(WAIT) ENDDO /* Check for object allocation */ IF COND(&FOR *EQ '*ALLOC') THEN(DO) IF COND(&OBJTYPE *EQ '*FILE') THEN(DO) ALCOBJ OBJ((&OBJLIB/&OBJ &OBJTYPE &ALLOC &MBR)) WAIT(0) MONMSG MSGID(CPF1002 CPF1040 CPF1085) EXEC(GOTO CMDLBL(WAIT)) ENDDO ELSE CMD(DO) ALCOBJ OBJ((&OBJLIB/&OBJ &OBJTYPE &ALLOC)) WAIT(0) MONMSG MSGID(CPF1002 CPF1040 CPF1085) EXEC(GOTO CMDLBL(WAIT)) ENDDO GOTO CMDLBL(ENDPGM) ENDDO /* Wait before attempting again */ WAIT: + DLYJOB DLY(&TRYWAIT) IF COND(&MAXNBRTRY *LT 99999) THEN(DO) CHGVAR VAR(&TIMEWAITED) VALUE(&TIMEWAITED + &TRYWAIT) IF COND(&TIMEWAITED *GE &MAXTIME) THEN(DO) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Maximum + time expired without satisfying wait condition') + MSGTYPE(*DIAG) SNDPGMMSG MSGID(CPF0002) MSGF(QCPFMSG) MSGTYPE(*ESCAPE) GOTO CMDLBL(ENDPGM) ENDDO ENDDO GOTO CMDLBL(LOOP) /* End program */ ENDPGM: + ENDPGM 
TechTalk: Don't Get Stood Up

Figure 1C Creating the Message File

 Figure 1c: Creating the Message File CRTMSGF MSGF(xxx/WAITOBJ) TEXT('Messages for WAITOBJ command') ADDMSGD MSGID(OBJ0001) MSGF(xxx/WAITOBJ) MSG('MEMBER parameter + must be entered if OBJTYPE(*FILE) is specified.') ADDMSGD MSGID(OBJ0002) MSGF(xxx/WAITOBJ) MSG('ALLOC parameter + must be entered if FOR(*ALLOC) is specified.') 
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: