4 top DB2 host variable points you need to know before write program

Db2 host variables

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:

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

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.

Also read

Advertisements

Author: Srini

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