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

     

Looping constructs

By Shawn M. Gordon

Inside VESOFT covers tips and techniques you can use with VESOFT’s products, especially MPEX. As always, I am totally open to getting input from you users of MPEX, Security/3000 or VEAudit/3000 — it helps me learn, too. Send me your tricks, and we’ll get a “3000 for 2000” cap out to you as our thanks.

First the big news. There is a new version of MPEX available for MPE/iX 6.5 that is supposed to handle the large files that are now available. I don’t have 6.5, the new MPEX or enough disc space to test it, so I can’t really tell you anything more — except I don’t recommend an ALTFILE of a 20Gb KSAM file.

I’m going to talk about the various looping constructs in the VESOFT product line and how you can make use of them. First there is the %WHILE...%ENDWHILE, which operates pretty much the same as the one in the CI. It can be used in MPEX and STREAMX most usefully, and in any situation where you need a general purpose loop. Here is a simple example:

%SETVAR I 0
%WHILE I<10
%>BUILD TEST!I
%>SETVAR I I+1
%>ENDWHILE

Next there is the %REPEAT...%FOREACH loop. This reminds me of the “for I =1 to 10..next I” type loop in BASIC. However, as most things in MPEX go, it can be stretched much further: for example:

%REPEAT
%>ECHO Creating group and user for !NAME %>NEWGROUP !NAME
%>NEWUSER !NAME; HOME=!NAME
%FOREACH NAME=BILL,GEORGE,SUE

My all-time favorite and most used tool is the %REPEAT...%FORFILES loop. This is where you can create command files that operate on file sets for special-purpose issues. As you work more and more with MPEX, you will find yourself turning to this construct. Here is a simple example:

%REPEAT
%>ECHO ——-Processing file !MPEXCURRENTFILE %>FILE MYFILE=!MPEXCURRENTFILE
%>RUN MYPROG
%>FORFILES @.DATA-T@.DATA(NOT ISPRIV)

Next we have %REPEAT...%FORJOBS, which is very handy for working against job sets for a particular action that isn’t directly support by the ALTJOB/BREAKJOB/ABORTJOB/RESUMEJOB commands. As an example:

%REPEAT
%>ECHO ——-Processing job ![RJOB.FMTJOB] ![RJOB.FMTLOGON]
%>IF RJOB.INPRI=2 THEN
%> :ALTJOB ![RJOB.FMTJOB];INPRI=3
%>ELSE
%> :ABORTJOB ![RJOB.FMTJOB]
%>ENDIF
%>FORJOBS @.AP&WAIT

You have a flexible method for altering batch jobs or aborting them depending on their value.
The %REPEAT...%FORNUM command I don’t find as much use for, but it is handy for doing things sequentially and is much more similar to the “for I = 1 to 10..next I” construct I explained earlier:

%REPEAT
%>:BUILD TESTDAT!I; REC=-80,,F,ASCII
%>FORNUM I=1,9

Now %REPEAT...%FORRECS is one of those commands that I haven’t gotten around to using yet because I always forget about it. It’s a nice sneaky way to read a file and do some processing, for example:

%REPEAT
%>RUN MYPROG1; INPUT=PROCDATE
%>FILE DATAFILE=D!PROCDATE.DATA
%>RUN MYPROG2
%>FORRECS PROCDATE=MYFILE,OLD

The %REPEAT...%FORRECS construct performs a sequence of MPEX commands once for each record of a given file, with a given variable (for example, “CURRENTREC”) set to each record of the file:
%REPEAT
%>ECHO Processing !CURRENTREC
%>RUN MYPROG;INFO=”!CURRENTREC”
%>FORRECS CURRENTREC=DATAFILE,OLD

This will do the commands between “%REPEAT” and “%FORRECS” once for each record in the file DATAFILE, setting the variable CURRENTREC to the contents of the current record.

We now get to the only Security/3000-specific loop that I am aware of, %REPEAT...%FORPROFILES. This construct allows you to perform an arbitrary set of actions on SECURITY profiles. Although the %SEC CHANGE command lets you change large groups of profiles, and the %SEC LISTUSER lets you report on any set of profiles, there are still some limitations to these commands. The %SEC CHANGE command is limited to changing ALL the profiles in the profile set to have the SAME value, and the %SEC LISTUSER command displays profiles with only one format.

Using %REPEAT...%FORPROFILES, however, you can change the fields of each profile that qualifies with different values (the changes may even be based upon current values of other fields). Simple reports can be generated by using the %ECHO command to format and display the values of any field within the profile.

For example, let’s say you have a user defined field that contains a three-digit department code and you want to change it to be four digits by adding a “1” to the beginning of each code. The following loop will do just that:

%REPEAT
%SEC CHANGE !MPEXCURRENTPROFILE;DEPT=![“1”+PROFILE.UF(‘DEPT’)] %FORPROFILES @,@.@(UF(‘DEPT’)<>’’)

Now finally we are up to the three VEAUDIT-specific loops, they are:

%REPEAT ... %VEAUDIT FORACCTS
%REPEAT ... %VEAUDIT FORUSERS
%REPEAT ... %VEAUDIT FORGROUPS

Basically you have to own both MPEX and VEAUDIT for this to work, and you have to preface the FOR???? With VEAUDIT. Each construct lets you do “things” to MPE accounts, groups and users, for example:

%REPEAT
% COMMENT Copy a file into all groups (except DATA and PUB)
% COMMENT in the AP account
% :COPY CONTFILE.DATA.AP,CONTFILE.![RGROUP.GROUP].AP %VEAUDIT FORGROUPS @.AP-DATA.AP-PUB.AP

There you go, all the fun you could possibly hope for in a utility — until next month.

Shawn Gordon, whose S.M. Gordon & Associates firm supplies HP 3000 utilities, has worked with 3000s since 1983.
 


Copyright The 3000 NewsWire. All rights reserved.