Previous Topic: Statements Used in Cursor OperationsNext Topic: OPS/REXX Program That Demonstrates Cursor Operations


Guidelines for Writing Cursor Operation Statements

The following REXX program outline demonstrates how you might use SQL cursor operations.

Suppose that you want to examine the SYSTEMS table and write a message to the operator each time you find a system whose current state is DOWN but should be UP. You can do this using an SQL cursor operation, invoked by SQL statements in an OPS/REXX program as follows:

(first few lines of program)
.
.
ADDRESS SQL
  "DECLARE X CURSOR FOR"
  .
  .
ADDRESS TSO
  (TSO command)
  .
  .
ADDRESS SQL
  "OPEN X"
  .
  .
  "FETCH X INTO NAME"

Once the DECLARE CURSOR statement invokes the SQL host environment, subsequent SQL statements do not need to include the text ADDRESS SQL as long as the program does not switch to another default host environment.

However, because a statement invoking another host environment appears in the program above (the ADDRESS TSO statement shown before the SQL OPEN and FETCH statements), you have to invoke the TSO host environment with an ADDRESS statement and then switch back to the SQL host environment.

You can explicitly declare the host environment on each SQL statement by using the following form:

ADDRESS SQL 'sqlstatement'

It is a good idea to use the above form in a large program or a program that sends commands to several different host environments, since you will never send the wrong command to the wrong environment.