Please enable JavaScript to view this site.

R:BASE 11 Help

Navigation: Command Index > O

OPEN (Short Name: OPE)

Scroll Prev Top Next More

Use the OPEN command before using the cursor designated by the DECLARE CURSOR command.

 

OPEN

 

Options

 

cursorname

Specifies a 1 to 18 character cursor name that has been previously specified by the DECLARE CURSOR command.

 

RESET

Reopens a cursor with the current values of any variables referenced in the DECLARE CURSOR statement. This improves performance by eliminating the need to re-optimize the query.

 

About the OPEN Command

 

OPEN evaluates the SELECT clause of the DECLARE CURSOR command using the current values of any variables that it contains. Then OPEN stores that copy of the cursor definition and places the cursor before the first row.

 

After you close a cursor with the CLOSE command, you can reopen it by repeating the OPEN command. Every time you open a cursor, R:BASE reads the rows again, so that any changes you previously made through the cursor are visible when you look at the rows.

 

You can display all currently defined cursors with the LIST CURSOR command.

 

When using the RESET option, the WHERE clause is evaluated with the current values of any referenced variables, and the cursor is reopened without requiring a CLOSE command. The cursor is positioned at the beginning of the result set when the FETCH command is run.

 

Example

 

The following command lines show the OPEN command with the RESET option.

 

  DROP CURSOR c1

  DROP CURSOR c2

  SET VAR vc1custid INTEGER

  DECLARE c1 CURSOR FOR SELECT custid FROM customer

-- Selects the transaction rows for the customer

  DECLARE c2 CURSOR FOR SELECT transid, invoicetotal +

     FROM transmaster WHERE custid = .vc1custid

-- Process the query in cursor c1 and get the first custid

  OPEN c1

  FETCH c1 INTO vc1custid IND c1ind1

  WHILE sqlcode <> 100 THEN

  -- Process the query in c2. As each row is fetched in the

  -- customer table, the custid changes; each time

  -- the "OPEN c2 RESET command" processes the c2's query it

  -- retrieves different rows

     OPEN c2 RESET

  -- Fetch the transid (invoicenumber) and invoice total amount

     FETCH c2 into vtransid, vamt

     WHILE sqlcode <> 100 THEN

        WRITE .vtransid, .vamt

        FETCH c2 into vtransid, vamt

     ENDWHILE

  FETCH c1 INTO vc1custid

  ENDWHILE

  CLOSE c1

  CLOSE c2

  DROP CURSOR c1

  DROP CURSOR c2