Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 14:- Database Interface


DCLGEN

  • DCLGEN stands for Declarations Generator.
  • It is a tool that is used to generate COBOL copybook for DB2 table. This copybook will contain COBOL host variables structure that is map to the columns of DB2 table.
  • Host variables names are created by replacing underscore in DB2 column name with hyphen. Host variables data type is also auto-selected to best fit the data type of DB2 columns.
  • Once DCLGEN copybook is generated for a table, they can be included into all the COBOL programs where that table is used.
  • DCLGEN copybook can be included in COBOL program using INCLUDE statement.
  • If INCLUDE is used to copy DCLGEN, it must be used in DATA DIVISION.
  • Basic syntax of using INCLUDE statement:-

    EXEC SQL INCLUDE table-copybook END-EXEC.

  • Where, table-copybook is name of copybook that you want to be included and explained in program.
  • When INCLUDE is used (instead of COBOL ‘COPY’ statement) to include copybook in program, it gets expanded during the pre-compilation process.
  • Thus, it is preferable to use INCLUDE for table copybook as those are needed during pre-compilation process to support Embedded SQL statements used in program.
  • Example of DCLGEN file for EMP table (with COMMENTS being removed):-

    File:- USER.COPYLIB(DCLEMP) **************** Top of Data **************** EXEC SQL DECLARE EMP TABLE ( EMP_ID CHAR(05) NOT NULL, EMP_NAME CHAR(10) NOT NULL ) END-EXEC. ********************************************* *COBOL DECLARATION FOR TABLE EMP ********************************************* 01 DCLEMP. 10 EMP-ID PIC X(05). 10 EMP-NAME PIC X(10). ************** Bottom of Data ***************

  • Above copybook can be used in COBOL program WORKING-STORAGE SECTION as shown below:-

    EXEC SQL INCLUDE DCLEMP END-EXEC.






© copyright mainframebug.com
Privacy Policy