Building IBM COBOL applications on Windows

You can use the provided build scripts to compile and link Db2® API and embedded SQL programs. The scripts are in the sqllib\samples\cobol directory. The directory also contains sample programs that you can build with these files.

About this task

Db2 supports two precompilers for building IBM® COBOL applications on Windows, the Db2 precompiler and the IBM COBOL precompiler. The default is the Db2 precompiler. The IBM COBOL precompiler can be selected by uncommenting the appropriate line in the batch file you are using. Precompilation with IBM COBOL is done by the compiler itself, using specific precompile options.

The batch file, bldapp.bat, contains the commands to build a Db2 application program. It takes up to four parameters, represented inside the batch file by the variables %1, %2, %3, and %4.

The first parameter, %1, specifies the name of your source file. This is the only required parameter for programs that do not contain embedded SQL. Building embedded SQL programs requires a connection to the database so three optional parameters are also provided: the second parameter, %2, specifies the name of the database to which you want to connect; the third parameter, %3, specifies the user ID for the database, and %4 specifies the password.

For an embedded SQL program using the default Db2 precompiler, bldapp.bat passes the parameters to the precompile and bind file, embprep.bat.

For an embedded SQL program using the IBM COBOL precompiler, bldapp.bat copies the .sqb source file to a .cbl source file. The compiler performs the precompile on the .cbl source file with specific precompile options.

For either precompiler, if no database name is supplied, the default sample database is used. The user ID and password parameters are only needed if the instance where the program is built is different from the instance where the database is located.

The following examples show you how to build and run Db2 API and embedded SQL applications.

To build the non-embedded SQL sample program client from the source file client.cbl, enter:
   bldapp client
The result is an executable file client.exe. You can run the executable file against the sample database by entering the executable name (without the extension):
   client

Procedure

  • There are three ways to build the embedded SQL application, updat, from the source file updat.sqb:
    1. If connecting to the sample database on the same instance, enter:
         bldapp updat
    2. If connecting to another database on the same instance, also enter the database name:
         bldapp updat database
    3. If connecting to a database on another instance, also enter the user ID and password of the database instance:
         bldapp updat database userid password

      The result is an executable file, updat.

  • There are three ways to run this embedded SQL application:
    1. If accessing the sample database on the same instance, enter the executable name:
         updat
    2. If accessing another database on the same instance, enter the executable name and the database name:
         updat database
    3. If accessing a database on another instance, enter the executable name, database name, and user ID and password of the database instance:
         updat database userid password