Before you can use a host variable in an embedded SQL statement, you must declare it.
You reference host variables from embedded SQL statements. When you code a host variable name into an embedded SQL statement, it must be preceded by a colon (:) to enable the compiler to distinguish between the host variable and tables or columns with the same name.
EXEC SQL BEGIN DECLARE SECTION END-EXEC 01 id pic x(4). 01 name pic x(30). 01 book-title pic x(40). 01 book-id pic x(5). EXEC SQL END DECLARE SECTION END-EXEC . . . display "Type your identification number: " accept id. * The following statement retrieves the name of the * employee whose ID is the same as the contents of * the host variable "id". The name is returned in * the host variable "name". EXEC SQL SELECT emp_name INTO :name FROM employees WHERE emp_id=:id END-EXEC display "Hello " name. * 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