Understanding the power of REPEAT...FORFILES
Inside VESOFT covers tips and
techniques you can use with VESOFTs products, especially
That said, lets move toward what I hope to accomplish over the coming months. Obviously, a lot has been covered by Shawn over the past few years, but I am going to attempt to write this as if I were starting anew. Not that I am going to go back to the basics of VEsoft products, just that I will not shy from a subject because Shawn already did it.
To that end, I renew Shawns entreaty for input from the user community. If you have any ideas, hints, shortcuts, etc. that you wish to share, please let me know and Im sure we can reward you with some gewgaw we got at some obscure trade show.
About six years ago, when my supervisor was searching for programmers, she created a check-sheet of skills which we would ask job applicants to fill out. The sheet included a full range of e3000 skills Qedit, Supertool, PowerHouse, Adager, and of course MPEX. The applicants were asked to rate themselves from 0 to 6, with 0 being no knowledge and 6 being skilled enough to train other staff members in the intricacies of the tool
On more than one occasion, I interviewed an applicant who had rated his skill level as a 6 for MPEX. Since I at one time taught MPEX classes, I was always ready for the opportunity to burst that bubble with one question never failed me Explain the REPEAT...FORFILES command in MPEX. There was usually a blanched look on the applicants face and a mumble of something like, Maybe I rated myself too high on that.
I have been constantly amazed that MPEX users overlook this powerful set of commands. To put things in simple terms, I view MPEX as just a combination of the creation of an indirect file, and the execution of a REPEAT...FORFILES command on the entries in that indirect file. (I realize theres a lot more to it than that, but that takes it to an understandable level.) There are actually six REPEAT...FOR... commands, all of which perform basically the same type of function - FORFILES, FOREACH, FORJOBS, FORNUM, FORPROFILES and FORRECS. The syntax varies slightly on each, but the idea is the same give MPEX a command or set of commands and a list. MPEX will then perform that command or those commands on the list.
The REPEAT...FOR construct basically allows you to declare specific commands that are not necessarily part of the MPEX command set and do them repetitively on the selected set of files. All you do is place that command or commands between the REPEAT and the FOR statements and MPEX will perform them. MPEX variables and attributes can be used to address certain aspects of a file in the commands performed. (Note: My examples are use files. When run interactively, MPEX issues a > prompt after the REPEAT statement and it continues until you complete the command with the FOR statement.)
REPEAT...FORFILES has been very helpful in performing some repetitive tasks I have had to perform on an annual or semi-annual basis. These tasks were generally tedious creation of 12 empty databases from schema text files, for example. This involved first copying the 12 schema files from one account to the new, empty account. Then it was a matter of running DBSCHEMA 12 times followed by doing the create function in DBUTIL 12 times. I chose instead to set up a command file to do everything! The first part was simple the MPEX copy of the 12 schema files, stored in a different (source) account obviously, the files had to be released or the copy done with SM capability.
Now came the step where
REPEAT...FORFILES came in handy (although as youll see later,
FOREACH and FORRECS also could have worked quite nicely). I needed to
create the root file by running the schema through DBSCHEMA. I knew
in advance that all 12 of the schema text files ended in DDL (for
data definition language created with the SCHEMA function in
Adager). So I used this command:
So this step would create the 12 databases, thus doing everything in a command file instead of interactively running DBSCHEMA and DBUTIL 12 times each.
A second means of doing this would have been to create a file (here named THISFILE) containing the specific file names in it, whether (as here) the schema text files or the root files and then done:
And the third way to perform the
same function is with the REPEAT...FOREACH command. In this case you
declare the file names in the FOREACH statement.
Copyright The 3000 NewsWire. All rights reserved.