Exec sql and End exec

Question:
why do we declare include in between exec sql and end exec and why cant we declare copybook in place of include. Is their any reason why we declare include only

Answer:
INCLUDE is a pre-compiler statement so it should be coded within the scope of EXEC SQL and END-EXEC.

INCLUDE is expanded during pre-compilation tome but COPY is expanded during compilation time and so declaration of host variable in copybook will produce errors during pre-comilation.

Answer2:
It all has to do with the sequence of compiling a program with imbedded SQL. It is important to understand that a COBOL program with SQL statements will actually go through 2 steps in the compile process - The Pre-Compile(SQL) followed by the COBOL compile.The EXEC SQL END-EXEC and everything in between are not COBOL statements and the COBOL compiler will not recognize them. The Pre-compiler step takes the EXEC SQL statements and converts them to the equivalent source code that COBOL will understand. The converted output from the pre-compile is then passed to the COBOL compiler in the 2nd step. It is for this reason that any data areas needed by the Pre-Compile step need to be included via a EXEC SQL INCLUDE statement.If you are also writing CICS COBOL with SQL then you will have 2 pre-compile steps for CICS and SQL followed by a COBOL compile step.

No comments:

Post a Comment

Please Provide your feedback here