Generating declarations from Db2 tables, views, and aliases

You can generate copybooks, include files, macros, and C/C++ header files from database table information by using the Db2® utility DCLGEN. This utility makes it easier for you to include database table structures in your programs.

Before you begin

  1. Connect to a remote system.
  2. Connect to a database.
  3. Add the Data Source Explorer to your z/OS Projects perspective. On the menu bar, click Window (on Windows) or IBM Developer for z/OS (on macOS) > Show View > Data Source Explorer.

Procedure

To generate a copybook, include file, macro, or C/C++ header file by using the DCLGEN utility:

  1. From the Data Source Explorer, select a z/OS® database table, view, or alias.
  2. From the menu, click DCLGEN.
    The Generate Declarations wizard opens. Some of the fields in this wizard contain default values. These values are replaced with the values you enter and are saved for your next session.
  3. Complete the required fields and any other optional fields in the wizard.
    The following table describes the fields on each page.
    Table 1. Generate Declarations (DCLGEN) fields
    Page Field Description
    System Information System name The name of the z/OS system on which the Db2 table is located. To select a different system and database table, select a system name from the list. Click Connect to connect to the system.
      Db2 subsystem The name of the Db2 subsystem that you are connected to.
      Procedure The name of the JCL procedure to be run. The default is ELAXFDCL. For more information about available sample JCL procedures, see ELAXF* remote build procedures in the Host Configuration Guide.
      Step The JCL step to be run. The default value is DCLGEN.
      JCL job card The default JCL job card in use at your site. You can edit this JCL or add any JCL statements your site requires.
    Generated Output Language The language for the generated declaration. This list shows the languages that are supported by the DCLGEN utility.
    • IBMCOB - IBM® Enterprise COBOL for z/OS
    • PLI - IBM Enterprise PL/I for z/OS
    • C - IBM C/370
    • COBOL - IBM OS/VS COBOL
    • COB2 - Other COBOL languages
    For more information about the DCLGEN language options, see the Db2 command reference in the related topics.
      Output data set The name of the data set where the generated JCL is to be stored. Click Browse to select a data set name.
      Member The name of the partitioned data set member to contain the generated JCL.
      Password (if required) If your output data set requires a password, specify it here. This password is included in the generated JCL.
    DCLGEN Options Connection The Db2 subsystem that you are connected to.
      Schema and table The Db2 schema and table you selected.
      Data structure name A name for the generated data structure. The name can contain up to 31 characters.
      Prefix A prefix to be used to form field names in the data structure. The prefix can contain up to 28 characters and is concatenated with a 1-to-3-digit number to form field names. If you specify a prefix of ABC, for example, field names ABC1, ABC2, and so on, up to ABC999 are formed. See the COLSUFFIX option for more options for field names.
      DCLGEN options DCLGEN options for the generated data structure. The options available are described briefly. Refer to the Db2 command reference for the version of Db2 in use at your site for a complete description of these options.
      ACTION How the partitioned data set member that contains the generated data structure is to be created. Select REPLACE to replace an existing partitioned data set member with the member currently being generated or ADD to add the member name as a new member if it does not exist.
      String delimiter The host language string delimiter. This option is used for COBOL programs only. Select APOST to specify an apostrophe as the host language string delimiter or QUOTE to specify a quotation mark as the host language string delimiter.
      LABEL Whether to include column labels in the output as comments. Select YES to include the column labels or NO to omit them.
      DBCSSYMBOL The symbol that is used to denote a graphic data type in a COBOL PICTURE clause. Select G or N.
      DBCSDELIM Whether the DBCS table and column names in the generated DECLARE table statement are delimited. Select YES or NO.
      COLSUFFIX Whether to form field names by attaching the column name to the prefix specified in the Prefix field. Select YES to form field names by appending column names to the Prefix. If the prefix is ABC, for example, and a column name is EMPNO, the generated field name is ABCEMPNO. If no prefix is specified, DCLGEN issues a warning message and uses the column names as the field names. Select NO to use only the Prefix to generate field names.
      INDVAR Whether to create an indicator variable array for the host variable structure. Select YES or NO. If you select YES, the array name is the table name with a prefix of “I” (or DBCS letter “<I>” if the table name is double-byte).
  4. Click Finish to generate and submit JCL to create the generated declarations.
    The wizard generates the JCL and submits it to the remote system. If the job completes successfully, the generated data structure is saved in the output partitioned data set member that is specified on the Generated output page of the wizard.
  5. To see the job output, expand the JES > My Jobs filter in the Remote Systems view and double-click the job name to open the job output.
  6. To see the generated data structure, expand the MVS Files > My Data Sets filter to locate the partitioned data set and member name that is specified on the Generated output page of the wizard and double-click the member name to open it.