RPG (IBM i / AS/400) · DB2 SQLCODE

SQLCODE -518 - Statement Not in a Usable Prepared State

What does SQLCODE -518 - Statement Not in a Usable Prepared State mean in RPG (IBM i / AS/400)?

An EXECUTE or OPEN referenced a statement name from a PREPARE that either failed, was never issued, or prepared a statement type that can't be run that way - for example trying to EXECUTE a select-statement instead of opening a cursor for it.

SQLCODE -518 - Statement Not in a Usable Prepared StateDB2 for i · SQLRPGLE

Condition

An EXECUTE or OPEN referenced a statement name from a PREPARE that either failed, was never issued, or prepared a statement type that can't be run that way - for example trying to EXECUTE a select-statement instead of opening a cursor for it.

Fix

Check the SQLCODE from the PREPARE before trying to EXECUTE or OPEN against it, and use DECLARE CURSOR ... FOR the prepared statement plus OPEN for any dynamic SELECT rather than EXECUTE.

Related db2 sqlcode