The Declaration Generator automates the process of creating copybooks to declare host variables. You specify the table for which you want to generate a copybook and the Declaration Generator creates a copybook with data declarations that match the data names and types used in the XDB system. The Declaration Generator can be used interactively or in batch mode and can create a separate copybook for each table or one copybook containing declarations for many tables.
You can use the Declaration Generator to declare a table in C, COBOL or PL/I. For each language, the Declaration Generator creates a complete SQL DECLARE statement and the appropriate record definition (COBOL) or structure (C and PL/I). Depending upon the language, the following file types are created:
Language | Declaration File |
COBOL | Copybook file (.cpy file) |
C | Header file (.h file) |
PL/I | Include file (.inc file) |
You can run the Declaration Generator interactively (from a dialog box) or in batch mode (from the command line). Batch mode is useful for generating declarations for many tables at one time.
Regardless of whether you run the Declaration Generator interactively or in batch mode, you must specify the following:
You can specify language-dependent options. For example, when you create a COBOL declaration, you can select the computation type for whole-number fields; when you create a C declaration, you can select upper or lowercase element names.
To access DB2 data from an application program, you need to create host variables that are common data items between the SQL statements in your query and in your program. A data item declaration in the program must have the same name as that used in your SQL statement and must conform to the relevant DB2 data type for the column concerned.