Page 1 of 1

Can you re-use cursors?

PostPosted: Tue May 17, 2011 11:35 pm
by dbhasty
Hi

I basically want to know if you can re-use a cursor? If you do you need to close the cursor then re-open it or can you just run the fetch part again.

In working storage i have array/table.
01 WS_TABLE.
05 EMP_NUM X(5)OCCURS 10 TIMES.
05 NAME OCCURS 10 TIMES.



Here is the cursor set up
EXEC SQL DECLARE C1 CURSOR WITH ROWSET POSITIONING FOR
SELECT NAME, EMP-NUM
FROM CORPORATE.EMPLOYEE
WHERE DEPT = :WS-DEPT
END-EXEC.

EXEC SQL OPEN C1 END-EXEC.

EXEC SQL FETCH FIRST ROWSET FROM C1 FOR 10 ROWS INTO :NAME, :EMP-NUM END-EXEC.

EXEC SQL CLOSE C1 END-EXEC.


I want to run it for when WS-DEPT is set to '010' and then run it again for when WS-DEPT is set to '020'. Can this be done using one cursor?


Many thanks
DB

Re: Can you re-use cursors?

PostPosted: Wed May 18, 2011 3:15 am
by dick scherrer
Hello,

Close the cursor.

Set the new search value.

Open the cursor.