Exec sql and End exec

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

Questions by Gowrikalepalli

Showing Answers 1 - 12 of 12 Answers

Radha3

  • Jul 17th, 2008
 

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.

memays

  • Apr 30th, 2009
 

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.   

  Was this answer useful?  Yes

ABSS1981

  • Sep 18th, 2009
 

In addition to the answers posted one of the additional things to have an INCLUDE between EXEC SQL and END-EXEC is that:

You INCLUDE most likely will be a DCLGEN and it is going to have non COBOL language variables that is the table column names which you are likely to refer in the COBOL DB2 program.
In order to enable the compiler understand the non COBOL words (underscore in the table column names) the INCLUDE is between EXEC SQL and END-EXEC

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions