Previous Topic: Use Substring Notation to Compare a Variable and a StringNext Topic: Search a String for Another String


Compare Screen Data with a String

In many programs, you will want to know whether the current screen is the one the program will be interacting with. For example, before a program that signs a user on to an application enters the user ID and password, it must determine that the current screen is the application signon screen. To do this, it searches the screen for data that identifies the signon screen.

The command for searching the screen is SEARCH. For example, the following statement determines whether the current screen contains the string "ENTER USERID":

SEARCH 'ENTER USERID'

The result of the search is represented by a condition code that indicates whether the string is present. The next statement, which is a BRANCH statement, uses this condition code to determine where to go next.

The following program examines the current screen to determine if it contains the string "ENTER USERID." If the string is present, the program branches to the statement labeled TSO, which enters the user ID, then goes to the next statement, which enters the password. If the string is not present, the program executes the statement that immediately follows the BRANCH statement. In this case, the next statement is the STOP statement, which terminates the program.

          SEARCH 'ENTER USERID' 
          BRANCH EQ,TSO 
          STOP 
TSO       KEY '&USERID' 
          ENTER 
          KEY '&PASSWORD' 
          ENTER 
          STOP

Only two condition codes are valid SEARCH results:

EQ

Inidicates that the string is present on the current screen

NE

Inidcates that the string is not present on the current screen.