Fujitsu J2X0-1634-01EN Computer Accessories User Manual


 
4.3 Opening and Closing a Cursor
Before data can be manipulated using a cursor, the cursor must be opened using an OPEN statement. After data has
been manipulated, the cursor must be closed using a CLOSE statement.
Opening a cursor
Use an OPEN statement to begin using a cursor. The cursor table specified in the cursor declaration is created as
soon as the OPEN statement is executed. The following is an example in which STOCK_CSR is opened:
The cursor declaration specifying the cursor name must be coded before the OPEN statement in the coding sequence
for the application program. A cursor specified in an OPEN statement must be one that has never been opened or one
that has been closed by a CLOSE statement. If a cursor is opened more than once, an error occurs. Different cursors
can be opened at the same time.
Closing a cursor
Use the CLOSE statement to stop using a cursor. The following is an example of closing STOCK_CSR:
The cursor declaration specifying the cursor name must be coded before the CLOSE statement in the coding
sequence for the application program. A cursor specified in a CLOSE statement must be open. If a cursor that is not
open is specified in a CLOSE statement, an error occurs.
4.4 Positioning a Cursor and Fetching Data
Use the FETCH statement to manipulate data in the following ways:
· To position a cursor and fetch data from the row on which the cursor is positioned
· To position a cursor on the row to be updated and update data in the row using the UPDATE statement
· To position a cursor on a row and delete the row using the DELETE statement
The following is an example of specifying the FETCH statement:
Example 1:
In this example, a cursor is declared to fetch ITMNO and STOCKQTY for products with WHCODE "2"
from the STOCK table. The cursor moves one row at a time to fetch values.
50