DB2-Undefined Unusable Host Variable

In DB2, I got an error during pre-compilation – Undefined or Unusable host variable. I did research and shared resolution in this post.


In WHERE clause, the HOST VARIABLE data types should match the below rules, else you will get an error (i.e DB2 will recognize if host variable data-types are as per DCLGEN).

Define Host variable. Below is the list of rules.

  • Define the Host-variable name before you declare the cursor.
  • The value passed into Host-Variable should not cross 255 Bytes.
  • A proper declaration of Host-Variable is needed before using it in the SQL query.
  • The Data type of Host-variable passed CALL statement is not a CHAR or VARCHAR.
  • When you use STDSQL(YES) option for pre-compilation, you must declare Host-Variables in BEGIN/END sections.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.