Host variable declaration is one of the main step in developing application program using DB2. You add Host variables in application program why because, the data from database to be received by language which you are using , example COBOL or PLI. In simple terms Host variable is related to host language not related to SQL.
A host variable is a data item that you declare in a program for use within an SQL statement. You can:
Retrieve data into the host variable for your application program’s use
Place data into the host variable to insert into a table or to change the contents of a row
Use the data in the host variable when evaluating a WHERE or HAVING clause
Assign the value in the host variable to a special register. It is a storage area that DB2 defines for a process to hold information that SQL statements can reference.
Declaring host variable
01 empid pic x(06).
How to use host-variable in SQL
EXEC SQL SELECT EMPNO, LASTNAME, DEPT INTO :CBLEMPNO, :CBLNAME, :CBLDEPT FROM EMP WHERE EMPNO = :EMPID END-EXEC.
In DB2 COBOL or PLI program, the first precedence is DB2 pre-compiler. It creates DBRM for DB2 logic. The compiler creates link editor for COBOL logic.
- DB2 Five key areas to improve Performance
- Real logic you need to connect DB2 using PHP engine
- Top DB2 privileges really useful for certification seekers