Generating table and view declarations by using DCLGEN

Your program should declare the tables and views that it accesses. For C, COBOL, and PL/I programs, you can use DCLGEN to produce these declarations, so that you do not need to code the statements yourself. DCLGEN also generates corresponding host variable structures.

Before you begin

Requirements:
  • Db2 must be active before you can use DCLGEN.
  • You can use DCLGEN for table declarations only if the table or view that you are declaring already exists.
  • If you use DCLGEN, you must use it before you precompile your program.

Procedure

To generate table and view declarations by using DCLGEN:

  1. Invoke DCLGEN by performing one of the following actions:
    • To start DCLGEN from ISPF through DB2I: Select the DCLGEN option on the DB2I Primary Option Menu panel. Then follow the detailed instructions for generating table and view declarations by using DCLGEN from DB2I.
    • To start DCLGEN directly from TSO: Sign on to TSO, issue the TSO command DSN, and then issue the subcommand DCLGEN.
    • To start DCLGEN directly from a CLIST: From a CLIST, running in TSO foreground or background, issue DSN and then DCLGEN.
    • To start DCLGEN with JCL: Supply the required information in JCL and run DCLGEN in batch. Use the sample jobs DSNTEJ2C and DSNTEJ2P in the prefix.SDSNSAMP library as models.
      Requirement: If you want to start DCLGEN in the foreground and your table names include DBCS characters, you must provide and display double-byte characters. If you do not have a terminal that displays DBCS characters, you can enter DBCS characters by using the hex mode of ISPF edit.

    DCLGEN creates the declarations in the specified data set.

    DCLGEN generates a table or column name in the DECLARE statement as a non-delimited identifier unless at least one of the following conditions is true:
    • The name contains special characters and is not a DBCS string.
    • The name is a DBCS string, and you have requested delimited DBCS names.
  2. If you use an SQL reserved word as an identifier, edit the DCLGEN output to add the appropriate SQL delimiters.
  3. Make any other necessary edits to the DCLGEN output.

    DCLGEN produces output that is intended to meet the needs of most users, but occasionally, you need to edit the DCLGEN output to work in your specific case. For example, DCLGEN is unable to determine whether a column that is defined as NOT NULL also contains the DEFAULT clause, so you must edit the DCLGEN output to add the DEFAULT clause to the appropriate column definitions.

    DCLGEN produces declarations based on the encoding scheme of the source table. Therefore, if your application uses a different encoding scheme, you might need to manually adjust the declarations. For example, if your source table is in EBCDIC with CHAR columns and your application is in COBOL, DCLGEN produces declarations of type PIC X. However, suppose your host variables in your COBOL application are UTF-16. In this case, you will need to manually change the declarations to be type PIC N USAGE NATIONAL.