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 try to compile any SQL program, please make sure the following have been done:
If you have done all of the above steps, and get a COBDB006 error ("Required DB software db2agapi could not be found."), check the PATH statement generated by Studio Enterprise Edition from a Net Express command prompt. The PATH gets modified by Studio Enterprise Edition, and the directory where DB2 is installed might appear in the path statement beyond the 255-byte limit. Modify your PATH statement to ensure that the ..\SQLLIB\BIN directory is closer to the beginning of the PATH statement so that the database DLLs required to compile the program can be loaded.
Before you can compile a SQL program, you must have been granted authorization. This is usually done by the DB2 Database Administrator. You must have one of the following:
The user also needs all table privileges required to compile any static SQL statement in the application. Note that 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 company's DB2 Database Administrator.
You use the DB2 Compiler directive to give the DB2 ECM information such as the fact that you are using SQL, and which database you are using.
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:
Normally, programs containing embedded SQL are compiled in the same way as non-SQL programs, except that the DB2 Compiler directive is required. Special action is required only when creating an executable (binary) file when additional modules need to be linked in. Programs containing SQL code can be animated like any other program. You can examine host variables inside SQL statements as they are regular COBOL data items.