Previous Topic Next topic Print topic


DELETE (POSITIONED)

Deletes the row most recently fetched by a DataRows cursor.

Syntax:

>>-EXEC ADO-.--------------------.-DELETE---FROM---datatable_name---->
            +-USING dataset_name-+

 >----WHERE CURRENT OF---datarows_name---END-EXEC---><

Parameters:

dataset_name The DataSet reference to be used. If you do not specify dataset_name, the current DataSet is used.
datatable_name The same DataTable used in the SELECT FROM option (see DECLARE CURSOR).
datarows_name A previously declared, opened, and fetched DataRows cursor.

Comments:

EXEC ADO supports positioned delete; however, you cannot use host arrays with positioned delete.

The other type of DELETE used in standard EXEC ADO statements is known as a searched delete.

Example:

* Declare the cursor
     EXEC ADO
        DECLARE c1 DATAROWS FROM oline
     END-EXEC

* Open the cursor
     EXEC ADO
        OPEN c1 
     END-EXEC

* Modify the table using positioned updates and deletes
     PERFORM UNTIL EXIT
        * Delete row 1, 4, 7, ...
        EXEC ADO FETCH c1 INTO :oline END-EXEC
        IF SQLCODE NOT = 0
           EXIT PERFORM
        END-IF 
        EXEC ADO DELETE FROM oline WHERE CURRENT OF c1 END-EXEC
				
        * Update row 2, 5, 8, ...
        EXEC ADO FETCH c1 INTO :oline END-EXEC
        IF SQLCODE NOT = 0
           EXIT PERFORM
        END-IF
        MOVE 99 TO qty
        EXEC ADO UPDATE oline SET qty = :qty WHERE CURRENT OF c1 END-EXEC
				
        * Leave alone row 3, 6, 9, ...
        EXEC ADO FETCH c1 INTO :oline END-EXEC
        IF SQLCODE NOT = 0
           EXIT PERFORM
        END-IF
     END-PERFORM
Previous Topic Next topic Print topic