Host Variables


DB2 is an external system and can’t able to update from the program. COBOL program can’t able to retrieve the data directly by the SQL and can’t able to use it directly. There is a requirement to use intermediate fields to capture the data and then only it is ready to use in the program.

There is one more limitation for the working storage fields are, the declaration should match with the corresponding table column COBOL declaration. These variables are called as HOST VARIABLES. Equivalent data types in COBOL & DB2

CobolDb2
S9(8)COMPINTEGER
S9(4)COMPSMALLINT
X(n)NUM(n)
S9(m)V9(n)COMP-3DECIMAL(m,n)
X(n)CHAR(n)
X(n)+2VARCHAR(n)
X(8)TIME
X(10)DATE
X(26)TIMESTAMP

Database column equalent variable can be created by DCLGEN.

DCLGEN:

DCLGEN is the tool which is used to generate the COBOL copybook for the specific table. The columns names of the table will be remain same but the underscores are replaced by Hyphens. That copybook can be used in the program by using INCLUDE command like below.

EXEC SQL
	INCLUDE table-copybook
END-EXEC.

If INCLUDE is used to add the copybook to the program, the copybook will be expanded during the pre- compilation process. So INCLUDE needs to be used for the table copybooks too hence those also required to be expanded during the pre-compilation process.