Error
SQLCODE -510
Cursor with PREPARE not open
Explanation
FETCH or CLOSE on cursor with prepared statement that was not opened.
Solution
OPEN the cursor after PREPARE and before FETCH.
Example
Dynamic SQL cursor lifecycle