COBSQ0141: PREPARE before DECLARE is illegal.

The PREPARE statement must follow the DECLARE CURSOR that references it.

Move the DECLARE CURSOR statement before the PREPARE statement, then recompile the program.