DB2 Host Variables Here are 4 Key Points

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.

Host variables

A host variable is a data item that you declare in a program for use within an SQL statement. You can:

  1. Retrieve data into the host variable for your application program’s use

  2. Place data into the host variable to insert into a table or to change the contents of a row

  3. Use the data in the host variable when evaluating a WHERE or HAVING clause

  4. 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.

DB2 Pre-compiler

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 Host Variable these are 4 Key Points

Also read

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.