Inside VESOFT #03 (Searching for strings)
Shawn M. Gordon

There are three distint PRINT commands within MPEX that support searching for strings (among other things), and several functions that will work within the context of other commands. Most people know how to use %PRINT @.SOURCE;SEARCH=”VARIABLE”, but we can get much more sophisticated than that, first let’s start out with some of my personal favorites, keep in mind that ALL the various SEARCH criteria are available for each of the commands.

The PRINTO command is very useful, it is meant to be a short hand for looking at spoolfiles. The selection criteria can be either the DFID number or the job number. By using the keyword WAIT on an open spool file, you will see your display pause and wait for the spoolfile to generate more text. The update seems to be every couple of seconds, but it’s a very useful way for doing real time tracking of an executing job.

A couple of relatively recent extensions were added to PRINTO that are especially useful, they are the keyword IFLOW and the search parameters IFTRUE and IFFALSE. If you specify IFLOW as in %PRINT #J123;IFLOW then the false portion of any conditional logic in the job will display at low intensity so you can easily distinguish what got executed within the job.

You can take this concept even further by using %PRINT #J123;SEARCH=IFTRUE or IFFALSE. What this will do is totally eliminate the false or true (respectively) portion of the job from display, so you only have to deal with the pertinant parts of the job.

The companion to this is PRINTI, which will print the input job stream. This is usually handy for looking at a job that is scheduled or in a WAIT state and you want to know what it is going to do. You can reference it by either the #I number or the job number.

There are some very cool parameters that can be specified in conjuction with SEARCH, such as CONTEXT. You could do something like


This will print two lines before, and three lines after the text that is found. You can extend this with the PREV keyword, so say you are programming Pascal or C and want to find variable names that are within specific functions, well:

-----Printing MYPROG.SOURCE
15       WRITELN (CUSTNUM:10, ' NOT FOUND!');
939       IF CUSTNUM<>'XXX' THEN
992.44    CUSTNUM:='';

You can get really crazy with this stuff and embed expressions within the CONTEXT parameters, such as:

        CONTEXT=("PROCEDURE" or "FUNCTION"), (R[0:3]="END")

Here, MPEX will find all the lines containing the string “CUSTNO” or “CUSTNUM”, and then print all the lines from the immediately preceding line that contains “PROCEDURE” or “FUNCTION” and until the immediately following line that contains “END” as its first three characters.

Now the SEARCH engine itself is mostly available also within some other functions, namely FSEARCHSTRING, FCONTAINS, and FSEARCHEXP. This means that you can use file content criteria in functions such as COPY, PURGE, ALTFILE, LISTF, etc. There is a tremendous amount of power with this.

FSEARCHSTRING(S) [INT] Returns the number of lines containing the string S in the text of the current file:


finds all the files in the SOURCE group which have one or more lines containing the string ‘FOO’.

FCONTAINS(S) [BOOL] Returns TRUE if the string is in the file. For example:


finds all the files in the SOURCE group which have one or more lines containing the string ‘FOO’. This is equivalent to the example for FSEARCHSTRING, but you don’t include “>0” as part of the selection criteria.

FSEARCHEXP(S) [INT] Returns the number of lines that match the logical expression, just like the ones that can be passed to %PRINT ;SEARCH= specified by S. Remember, however, that since in this context S is a STRING, it must be enclosed in quotes:


will find all files that have at least one line containing EITHER the string ‘CUST-NO’ or the string ‘CUST-NAME’.

In fact, S can include (in addition to the logical expression used by ;SEARCH=) any of the MPEX %PRINT parameters (although not all of them are useful in this context).

%LISTF @.DOC.PROD(FSEARCHEXP(“CL’blue ox’;MAX=2”)=2), 3

shows you the create/restore/modify/access dates (“,3”) of all the files in the DOC.PROD group that contain at least two occurrences of the string “blue ox” (upper- or lowercase), and stops searching each file after finding two occurrences of the string.

Check out the HELP for PRINT, there are tons of nifty things, and I’ve just tried to get your mind thinking about the various possibilities. See you next time.