If your application consists of multiple ESL programs, you must specify a change to program action statement to tell ESL when to transfer control from one program to another. (If you want to exit from ESL completely, rather than transfer control to a new program, use the exit statement described in Exiting the Program.)
When ESL executes a change to program statement, it causes the current program to terminate. All objects, variables, constants, classes, patterns, and responses belonging to the program that is being left cease to exist. Note, however, that global variables still exist, started applications continue to run, and all input devices maintain their current state. The new program begins execution with its response to start statement.
The change to program statement, like other action statements, can be specified in a response definition or in an action routine definition or subroutine. Any statements specified after the change to program statement will be executed only if the change to program statement could not be performed, for instance if the new program could not be found. You might specify the following response definition:
response to Database_Key
send ExitCode to CurrentApp
change to program "Database"
copy "Could not find requested program" to InfoString
call DisplayError(InfoString)
Here, Database is a string literal identifying the name of an ESL program that interfaces a database retrieval application; ESL transfers control to that program. Note that the ESL program file extension is not required. The copy and subroutine call to DisplayError will not be performed unless the change to program statement was unsuccessful.
The value for the program name must be a string value and can contain a pathname. When specifying a path, include an extra backslash each time one is specified; for example:
change to program "c:\\ESL\\myfile"
This is necessary because a backslash by itself within an ESL string literal indicates an escape sequence, telling ESL to treat the next character as a special control character.
If you want to save the currently executing program as a new program with the current state of its objects and local variables, you can use the save program as statement before the change to program statement. (See Saving a Program in Progress.) Note that the save program as statement can be used in an action routine but not in a subroutine.