Before you can use a host variable in an embedded SQL statement, you must declare it. Host variable declarations should be bracketed by the embedded SQL statements BEGIN DECLARE SECTION and END DECLARE SECTION, for example:
EXEC SQL BEGIN DECLARE SECTION END-EXEC 01 id pic x(4). 01 name pic x(30). 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.