Building IBM COBOL routines on Windows

You can use the provided build scripts to compile and link Db2® API and embedded SQL programs in IBM® COBOL. 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, bldrtn.bat, contains the commands to build embedded SQL routines (stored procedures). The batch file compiles the routines into a DLL on the server. It takes two parameters, represented inside the batch file by the variables %1 and %2.

The first parameter, %1, specifies the name of your source file. The batch file uses the source file name, %1, for the DLL name. The second parameter, %2, specifies the name of the database to which you want to connect. Since the stored procedure must be built on the same instance where the database resides, there are no parameters for user ID and password.

Only the first parameter, source file name, is required. Database name is optional. If no database name is supplied, the program uses the default sample database.

If using the default Db2 precompiler, bldrtn.bat passes the parameters to the precompile and bind file, embprep.bat.

If using the IBM COBOL precompiler, bldrtn.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.

To build the sample program outsrv from the source file outsrv.sqb, connecting to the sample database, enter:
   bldrtn outsrv
If connecting to another database, also include the database name:
   bldrtn outsrv database
The batch file copies the DLL to the server in the path sqllib\function.

Once you build the DLL outsrv, you can build the client application outcli that calls the routine within the DLL (which has the same name as the DLL). You can build outcli using the batch file bldapp.bat.

To call the outsrv routine, run the sample client application by entering:
   outcli database userid password
where
database
Is the name of the database to which you want to connect. The name can be sample, or its remote alias, or some other name.
userid
Is a valid user ID.
password
Is a valid password for the user ID.

The client application accesses the DLL, outsrv, and executes the routine of the same name on the server database, and then returns the output to the client application.