Host variables are data items defined within a COBOL program. They are used to pass values to and receive values from a database. Host variables can be defined in the File Section, Working-Storage Section, Local-Storage Section or Linkage Section of your COBOL program and have any level number between 1 and 48. Level 49 is reserved for VARCHAR data items.
When a host variable name is used within an embedded SQL statement, the data item name must begin with a colon (:) to enable the Compiler to distinguish between host variables and tables or columns with the same name.
Host variables are used in one of two ways:
These are used to specify data that will be transferred from the COBOL program to the database.
These are used to hold data that is returned to the COBOL program from the database.
For example, in the following statement, :book-id is an input host variable that contains the ID of the book to search for, while :book-title is an output host variable that returns the result of the search:
EXEC SQL SELECT title INTO :book-title FROM titles WHERE title_id=:book-id END-EXEC