The ISPF Find Command

The Basic Search String

The find command is used to find and display the next occurrence of a character string in the data being browsed or edited. It can be abbreviated to f. The basic find command looks like this:

        Command ===> find xxx

The cursor is placed at the beginning of the string (in the above example, the next occurrence of the string "xxx"). The content of the screen will scroll automatically, if necessary, to bring the string into view. If the string contains spaces, quotes("), or apostrophes('), or the string is such that it might get confused with other keywords that can be added to the find command (eg. numeric) then the string needs to be delimited with either quotes or apostrophes. It doesn't matter which of these that you use except that where the string contains quotes you need to delimit it with apostrophes and vice versa. It is not possible to search for a string that contains both quotes and apostrophes. Delimiting a string is always valid so if you are not sure if delimiters are required then add them anyway.

To search for the same string as in the immediately previous find command you don't have to enter the string again, instead you can just enter an asterisk (*) in place of the string. This is useful if you want to change the direction of the search (find * prev) or change the columns to be searched (find * 25 35). For example:

Command ===> find "my way"
to find a string which contains a blank.
Command ===> find "McDonald's"
to find a string which contains an apostrophe.
Command ===> find '"Microsoft"'
to find a string which contains quotation marks.
Command ===> find '*'
to find an asterisk (and not the previous string).
Command ===> find 'all' prev
to find the previous occurrence of string "all".
Command ===> find all 'prev'
to find all occurrences of the string "prev".

 

Qualifying the Search String

You can use a find command to search for a string of hexadecimal digits. A hex string is a delimited string that is preceded or followed by the letter x (eg. x'0a19'). A hex string must contain only hexadecimal digits (0-9, A-F) and there must be an even number of digits. Either upper or lowercase letters can be used for a-f (which represent the hex numbers 10 through 15 respectively). A hex string is invalid if it contains an odd number of characters or characters that do not represent hex digits.

You can search for an occurrence of a type of string rather than a specific value using a picture string. A picture string is a delimited string that is preceded or followed by the letter p. A picture string can contain blanks, alphabetic and numeric characters which represent themselves, or any of the special characters listed below, each of which represents a class of characters.

You can enforce a match on the case of the string you are searching for by using a character string. A character string is a delimited string that is preceded or followed by the letter c. With a character string, only strings that match exactly (including case) will be found.

You can disregard the case of the string you are searching for by using a text string. A text string is a delimited string that is preceded or followed by the letter t. When a text string is specified upper and lower case characters are treated as being identical with one another (eg. t'a' matches both 'a' and 'A'). A string that is not delimited or which does not contain a qualifier will normally be treated as a text string.

 

Restricting the Search

You can limit the lines within a file that are to be searched by specifying labels in the find command. There are three system labels that you can use. These are .zfirst (abbreviated .zf) which represents the top of the file, .zlast (abbreviated .zl) which represents the end of the file, and .zcsr which represents the line on which the cursor can be found. You can also add your own user labels to the file by typing the label into the line command field at the left of the line to which you want it to apply. You then specify the two labels that you want to use as the upper and lower boundaries for the search into your find command to restrict your search to that part of the file. It doesn't matter which order you enter these labels as the identified range will be the same regardless. Note that two labels must be specified for the command to be valid. A valid user label name starts with a dot, contains one to five alphabetic characters, and does not start with .z. Labels may only be assigned to data lines. They may not be assigned to special lines (=COLS>, =MASK>, =TABS>, etc.).

You can limit the columns that are searched by entering a pair of column numbers indicating the first and last columns to be searched. The string will be found if it is completely contained within the designated columns. If columns are not specified, the columns to be searched will default to the columns defined by the BOUNDS line. If only one column number is specified then the string must start in that column.

 

Qualifying the Direction of the Search

The find command searches for the next occurrence of the specified character string, starting at the top of the displayed page (if the cursor is on the command line), or starting at the cursor position (if the cursor is within the data portion of the display). You can change the direction and scope of the search by entering one of the following optional parameters: next to find the next occurrence of the string (the default), prev to find the previous occurrence of the string starting from the current location, first to find the first occurrence of the string within the file, last to find the last occurrence of the string within the file, all to find the first occurrence of the string and also report on how many occurrences of the string exist within the file. Note that if the area to be searched is restricted using labels and column numbers that the results will be relative to the selected portion of the file rather than to the whole file.

 

Further Qualifying the Search

Normally, any occurrence of the string within the area to be searched will be returned as a match. You can restrict the search further by using one of the following optional parameters: chars match on the string wherever it occurs (the default), word matches only if the occurrence makes up a complete word (ie. is preceded and followed by non-alphabetic characters), prefix (abbreviated pre matches only when the string starts a word (ie. is preceded by a non-alphabetic character), suffix (abbreviated suf) matches only when the string ends a word (ie. is followed by a non-alphabetic character).

You can also restrict the search to only excluded lines by specifying the optional parameter x or ex or to only non-excluded lines by specifying the optional parameter nx. Note that using the find command to locate occurrences of a string will automatically unexclude any excluded lines in which the string is found. You can automatically exclude all of the lines in which the string is found by using the exclude command (which can be abbreviated x) instead of the find command. All of the parameters available to the find command are also available for the exclude command.

 

Repeating the Find Command

The rfind (repeat find) command can be used to repeat the last find command that was entered. Since this command is sensitive to the current position of the cursor, it is normally entered via a PF key. (The default key used for this is PF5 or PF17). By pressing this PF key repeatedly, you can find successive occurrences of a specified character string. After the "first" occurrence of a character string has been found, this key will find the "next" occurrence. After the "last" occurrence of a character string has been found, this key can be used to continue the search, wrapping around from the bottom line to the top line (or if the original direction of the find was toward the top of data, wrapping from the top line to the bottom line).

 

An Example Find Command

The following find command illustrates the use of all of the types of optional parameters specified above to search between the current line and the end of the file for all words starting with Child (case specific) that occur between columns 25 and 60 of the file. Assuming that all lines of the file have been previously excluded this command will unexclude all of the lines that satisfy the search.

f all c'Child' .zcsr .zl 25 60

Note that the parameters specified after the f can be specified in any order and the exact same search results will be returned.

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate