Compiling your SQL program with the COBOL Compiler is logically equivalent to two steps: precompiling to change SQL lines into host language statements, and then compiling the resulting source. These two steps actually occur in a single process, which is performed by the COBOL Compiler in conjunction with the DB2 ECM.
Before you attempt to compile any SQL program, please complete these tasks to ensure you can connect to the database:
Also before compiling, ensure that you log into DB2 with the appropriate authorization. You must have one of the following:
Individual database users who compile must have the table privileges required to compile any static SQL statement that appears in the code. Privileges granted to groups are not used for authorization checking of static SQL statements. If a program fails to compile because of lack of authority on an SQL object, please contact your DB2 Database Administrator.
If you are using the API calls introduced for DB2 LUW version 7.1, the DB2 ECM calls an IBM module to validate them. If the DB2 ECM finds an error in the directive syntax, it displays a -104 SQLCODE error message:
Programs containing embedded SQL are compiled using the DB2 Compiler directive. Additional action is required when creating an executable (binary) file that requires linking to additional modules (see Linking).
You can debug programs containing SQL code just as you would any other program, and can examine host variables inside SQL statements as regular COBOL data items.