Rules for host variables in an SQL statement
Use host variables in embedded SQL statements to represent a single value. Host variables are useful for storing retrieved data or for passing values that are to be assigned or used for comparisons.
When you use host variables, adhere to the following requirements:
- You must declare the name of the host variable in the host program before you use it. Host variables follow the naming conventions of the host language.
- You can use a host variable to represent a data value, but you cannot use it to represent a segment, view, or field name. You can specify segment or field names at run time by using dynamic SQL.
- To use a host variable in an SQL statement, you can specify any valid host variable name that is declared according to the rules of the host language.
- A colon (:) must precede host variables that are used in SQL statements so that IMS can distinguish a variable name from a field name. When host variables are used outside of SQL statements, do not precede them with a colon.
- To optimize performance, make sure that the host language declaration maps as closely as possible to the data type of the associated data in the database.
- For assignments and comparisons between an IMS field and a host variable of a different data type or length, expect conversions to occur.