Previous Topic Next topic Print topic


FETCH

Transfers all or a subset of a DataRows cursor into host variables or host arrays.

Syntax:

>>--EXEC ADO--.-------------------.----------------->
              +-FOR :host_integer-+

 >-FETCH-------.----------.---.----------.—VALUES--->
               +---SAME---+   +-CURRENT--+
               +---LAST---+   +-DEFAULT--+
               +---PRIOR--+   +-ORIGINAL-+
               +---FIRST--+   +-PROPOSED-+
               +---NEXT---+ 

 >--.------.—-datarows_name--.---------------.------>
    +-FROM-+                 +-(column_list)-+


 >--.--------------------------------.---END-EXEC---><
    |      +--- , -----+             |
    |      V           |             |
    +-INTO :col_value_hv-------------+
			

Properties:

:host_integer A host variable that specifies the maximum number of host array elements processed. Must be declared as PIC S9(4) COMP-5 or PIC S9(9) COMP-5.
datarows_name A previously declared and opened DataRows cursor
column_list A list of one or more columns for which data is to be retrieved. The column list determines the order in which values are received. Items in the column list must be enclosed in parentheses. If no column list is given, all of the columns in the receiving table (in DECLARE DATATABLE order) are assumed.

The column list is only necessary when some but not all of the columns in the DataRows cursors are to retrieve data.

:col_value_hv Identifies one or more host variables to receive the data from the columns.

Comments:

This statement is similar to the embedded EXEC SQL FETCH statement.

After execution, SQLERRD(3) contains the number of elements processed. For FETCH it is the number of rows actually fetched.

Example:

* Declare a cursor for a given SQL statement.
     EXEC ADO
        DECLARE drCust DATAROWS FROM Customers
     END-EXEC

     EXEC ADO OPEN drCust END-EXEC

* Fetch the current values from the cursor into the host variables
* and if everything goes ok, display the values of the host
* variables
     PERFORM UNTIL EXIT 
        EXEC ADO
           FETCH NEXT drCust (CustomerID, CompanyName) 
           INTO :Customers-CustomerID, :Customers-CompanyName
        END-EXEC
        IF SQLCODE < 0 or SQLCODE = 100
           EXIT PERFORM
        END-IF
        DISPLAY "Customer ID  = " Customers-CustomerID " Company Name = " Customers-CompanyName
     END-PERFORM
Previous Topic Next topic Print topic