| Front Page | News Headlines | Technical Headlines | Planning Features | Advanced Search |
Nobix Sponsor Message

     

Toying with REPEAT...FORNUM

By Steve Hammond

Call it fate, call it karma, call it synchronicity. Call it coincidence, call it being a smart user (nah, not that!).

Last month, within an hour of finishing the column on REPEAT...FOR commands in MPEX, I encountered a work circumstance where I needed to use the REPEAT...FORNUM command. The circumstance was fairly simple — 20 files whose names were FILEnn, where the ‘nn’ signified consecutive numbers from 1 to 20. I needed to rename the files SERnn. Now, I really didn’t want to do 20 renames if I could do the whole thing in one MPEX command.

But it actually took a little playing before I got it right. My first attempt was:

REPEAT
rename FILE!zz, SER!zz
FORNUM zz=1,20

Simple enough — just do 20 renames in the repeat and the work is done. Wrong! Unfortunately, the argument for FORNUM is always an integer, so the whole thing blew up on the first rename because it was looking for FILE1, not FILE01! I toyed with the idea of doing it in two passes — the first for 1 through 9 and the second for 10 through 20.

But, MPEX supports standard IF...ELSE...ENDIF processing inside the REPEAT...FOR structure, so I was able to get it all done in one command:

REPEAT
if !zz < 10
rename FILE0!zz, SER0!zz
else
rename FILE!zz, SER!zz
endif
FORNUM zz=1,20

That wasn’t so hard, and it did make me think about how we do other repetitive steps in our processing. A lot of our jobs do multiple renames and I am going to take the opportunity to examine those jobs to streamline any of them.

The FORNUM command has more power than just this. The variable actually has three arguments — the first is the starting value, the second is the ending value and the final is the increment. So FORNUM zzz=2,10,2 will do five iterations with a value of 2, 4, 6, 8 and 10. It also accepts negative increments. So FORNUM zzz=10,2,-2 will use the value of 10, 8, 6, 4 and 2. I can’t honestly think of a reason to do something like that in reverse order, but I am also sure as soon as I make such a statement, I will be deluged with valid circumstances for such commands. Suffice it to say, it’s out there and you can use it.

The next command is REPEAT...FORJOBS. Just as it sounds, REPEAT...FORJOBS allows you to perform commands upon sets of jobs/sessions. The attribute and user definitions are obviously different from those for files, but the base idea is still the same.
Just to play with it, I tried:

REPEAT
showjob ![rjob.fmtjob]
FORJOBS @.FINANCE

This basically does a showjob for every job and session on the system logged on into the FINANCE account. You can refine the job definitions by using the job/session attributes as listed in the Security/3000 manual.

Going back to the last example, if I only wanted the jobs, it would be:

REPEAT
showjob ![rjob.fmtjob]
FORJOBS @.FINANCE&BATCH.

The ‘BATCH’ tells it only to look for the jobs (the opposite of BATCH is ONLINE). You can also look for WAIT, SCHED, SUSP, INTRO and EXEC states. You can define it by the log in — @,MANAGER.@ will give you anything logged on as the user MANAGER, while STEVE,@.@ will give you anything signed on with the session or job name of Steve. You can even drill down to devices or capabilities.
You could use this to perform a more precise TELL command than is available in MPE/iX:

REPEAT
tell ![rjob.fmtjob] Log off for the backup
FORJOBS @.CLERK.ENTRY&ONLINE

The rjob variables are similar to the rfile variables I mentioned last month. These are how you define the job, although in most cases you will use the rjob.fmtjob variable since that is the job/session number and most MPE/iX functions use the job/session number as their parameters.

The last REPEAT...FOR command is REPEAT...FORPROFILES. This is used in conjunction with Security/3000, the companion to MPEX. You can perform various commands upon a set of Security/3000 profiles inside the REPEAT...FOR. You would generally use the SEC CHANGE or SEC DELETE commands that are part of the overlap between MPEX and Security/3000.

To define the profile set, you would use the profile attributes as used in Security/3000. These include anything from account name to the date of the last password change. You use the variable MPEXCURRENTPROFILE to address the selected profile in the command.

I’d like to add a couple of hints. Don’t expect the MPEXNUMSUCCEEDED variable to work inside these REPEAT...FOR loops. My tests have shown that it gets reset to 1 on each iteration. If you need to do some counting, set up your own variable inside the REPEAT...FOR loop and examine it during or after processing.

Secondly, and probably more importantly, even though you can do the REPEAT...FOR commands ‘interactively,’ I advise you not to do so, if just for sanity’s sake. Any typos on an earlier line are impossible to correct and can do any number of interesting things. Instead, create a command file using your editor. Then start up MPEX and ‘USE’ the file.

I go one step better since I use Robelle’s Qedit, which has been ‘hooked’ to MPEX. (If you don’t know about ‘hooking’ a program to MPEX, do ‘HELP HOOK’ inside MPEX and select ‘MPEX HOOK’ for the details.) So I create and keep my use file (let’s call it RPTFILE) and then at the Qedit prompt, I type “%use RPTFILE” to start up MPEX and use the command file. The results are displayed and control passes back to Qedit. It’s much easier to test and saves a lot of anguish.

I hope you have seen how to deal with redundant functions or commands in the work environment on the HP e3000, and how MPEX makes it easier for us to be redundant. (Hmmm… that doesn’t sound the way I think it should, does it?)

Steve Hammond does a lot of REPEAT..FORs in his life and in his job as a system manager for a trade association in Washington, DC.


Copyright The 3000 NewsWire. All rights reserved.