---
title: "DB2-Undefined Unusable Host Variable"
description: "Rules to define DB2 host variables. Read now."
url: https://srinimf.com/2011/12/11/db2hostvariable/
date: 2011-12-11
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2011/12/pexels-photo-4027658.jpeg?fit=1880%2C1253&ssl=1
categories: ["DB2"]
tags: ["Db2 Tips", "Declare", "host variables", "select", "sql", "undefined", "unusable"]
type: post
lang: en
---

# DB2-Undefined Unusable Host Variable

In DB2, I got an error during pre-compilation – Undefined or Unusable [host variable](https://srinimf.com/2018/05/10/4-top-db2-host-variable-points/). I did research and shared the resolution in this post.

Related[COBOL-DB2 Program: SQLCA is Not Mandatory Why](https://srinimf.com/2016/02/21/how-to-get-sqlcode-in-db2-cobol-program-without-sqlca/)

---

**I**n the 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](https://srinimf.com/2022/01/01/how-to-create-type-data-type-in-plsql/) 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.

[**32 Complex SQL Queries**](https://srinimf.com/e-books/)

**Related Posts**

- [DB2 Host Variables Here are 4 Key Points](https://srinimf.com/2018/05/10/4-top-db2-host-variable-points/)DateMay 10, 2018
- [DB2 Tutorial For Software Developers (5 of 5)](https://srinimf.com/2015/08/16/mainframe-db2-tutorial-for-software-developers-5-of-5/)DateAugust 16, 2015
- [COBOL-DB2 Program: SQLCA is Not Mandatory Why](https://srinimf.com/2016/02/21/how-to-get-sqlcode-in-db2-cobol-program-without-sqlca/)DateFebruary 21, 2016

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2011%2F12%2F11%2Fdb2hostvariable%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2011%2F12%2Fpexels-photo-4027658.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=DB2-Undefined%20Unusable%20Host%20Variable)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2011/12/11/db2hostvariable/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2011/12/11/db2hostvariable/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2011/12/11/db2hostvariable/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2011/12/11/db2hostvariable/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20DB2-Undefined%20Unusable%20Host%20Variable&body=https%3A%2F%2Fsrinimf.com%2F2011%2F12%2F11%2Fdb2hostvariable%2F&share=email)
-

### Like this:

Like Loading…
