DB2 Host Variables Example
DB2 Host Variables
Scenario1 - INSERT Statement Using Host Variables.
... EXEC SQL INSERT INTO Employees (Emp_ID, Emp_Name, Salary) VALUES (:WS-EMP-ID, :WS-EMP-NAME, :WS-SALARY) END-EXEC. ...
The host variables (WS-EMP-ID, WS-EMP-NAME, and WS-SALARY) are used to insert the input data to the Employees table.
Scenario2 - SELECT Statement Using Host Variables.
... EXEC SQL SELECT Emp_Name, Salary INTO :WS-EMP-NAME, :WS-SALARY FROM Employees WHERE Emp_ID = :WS-EMP-ID END-EXEC. ...
WS-EMP-ID provides the input value to identify the employee. The result (employee name and salary) is retrieved into WS-EMP-NAME and WS-SALARY.