Page 1 of 1

Why to use DB2 DCLGEN instead of COPY?

Posted: Sun Nov 22, 2020 4:08 pm
by Kamini Gupta
Hi,

Why to we use DB2 DCLGEN instead of COPY? Can not that make just same impact?

Re: Why to use DB2 DCLGEN instead of COPY?

Posted: Thu Nov 26, 2020 6:56 am
by Robert Sample
SQL statements are run through a preprocessor before the COBOL compile is done. The COPY statement is a COBOL verb and hence will not be invoked until the compile, which is after the preprocessor has completed. So using a COPY instead of DCLGEN means nothing will be available to SQL since the preprocessor will not have anything to work with.

Re: Why to use DB2 DCLGEN instead of COPY?

Posted: Fri Nov 27, 2020 5:26 pm
by Kamini Gupta
Thanks Robert. But if use COPY COPYBOOK with DCLGEN variables, when they will be used by program, program will get them and it will work, right?

Re: Why to use DB2 DCLGEN instead of COPY?

Posted: Tue Dec 01, 2020 10:14 pm
by Robert Sample
The IBM manual at https://www.ibm.com/support/knowledgece ... clgen.html says
The declarations generator (DCLGEN) produces an SQL DECLARE TABLE statement and a COBOL, PL/I, or C data declaration for a table or a view named in the catalog.
So the DCLGEN does the SQL DECLARE TABLE for which the fields can then be referenced in a copy book.