The ANSI and DB2 SQL modes require a result table generated using a DECLARE CURSOR statement to be closed using a CLOSE statement before this result table name can be used to open a new result table within the same transaction.
Insert a CLOSE statement into the application.