Compiling and Linking Stored Procedures under DB2 LUW

To compile and link a COBOL stored procedure using DB2 LUW:

  1. Add the program you want to use as a stored procedure to a Visual COBOL project.
  2. Set the project properties as follows:
    • If your program does not contain a $SET DB2(DB) statement, set this directive on the SQL tab by selecting the DB2 option for the ESQL Preprocessor field.
    • If you have 64-bit DB2 LUW installed, but you are building a 32-bit application, you need to update your project properties to specify the fully qualified path and filename of the 32-bit version of the db2api.lib file, which is a part of your DB2 installation. To do this, open the project properties and type the information into the Link with libs field on the COBOL Link tab.
  3. Build the project.
  4. At a command prompt or using Windows Explorer, copy the generated .dll file from its output location (the default is projectpath\bin\x86\Debug) to the SQLLIB\FUNCTION subdirectory of your DB2 installation directory.
Note: If your program contains stored procedure CALL statements, you must specify the CALL_RESOLUTION DB2 directive to avoid an SQL0204 error.
Attention: By default, after calling a stored procedure, DB2 LUW does not unload it until DB2 LUW is stopped. To avoid problems with copying the file, you can do one of the following if you are not in a production environment:
  • From a command prompt with DB2 administrator privileges:
    1. Execute db2stop.
    2. Copy the stored procedure binary file.
    3. Execute db2start.
  • From a command prompt configured for the DB2 LUW environment, execute:

    db2 update dbm cfg using KEEPFENCED NO

    Warning: Do not execute the db2 update command in a production environment. Doing so results in significant performance degradation. Refer to your IBM documentation for more information on this command.