IBM Books

Application Building Guide


IBM VisualAge COBOL for OS/2

This section contains the following topics:

Using the Compiler

These points will help you use the IBM VisualAge COBOL compiler with DB2.

Workaround for Creating Bind Files

When creating applications using DB2 for OS/2 and IBM Cobol, the DB2 precompiler will often fail to create bind files. This is due to a file handle limit within OS/2.

The fix is to make OS/2 allow more file handles on the machine perfoming the compiling. The line:

   SET SHELLHANDLESINC=20

should be inserted into the CONFIG.SYS file on the machine where DB2 for OS/2 is installed. Alternately, one can use the NODATA option when compiling (this is an IBM Cobol option).

Embedded SQL and DB2 API Calls

If you develop applications that contain embedded SQL and DB2 API calls, and you are using the IBM VisualAge COBOL compiler, keep the following points in mind:

DB2 API Applications

The command file bldapicb.cmd, in %DB2PATH%\samples\cobol, contains the commands to build a DB2 API program. The parameter, %1, specifies the name of your source file.

@echo off
rem  bldapicb command file
rem  Builds a COBOL program that does not contain embedded SQL
rem  Usage: bldapicb <prog_name>
 
if "%1" == "" goto error
 
rem Compile the checkerr error checking utility.
cob2 -c -g -qpgmname(mixed) -qlib -I%DB2PATH%\include\cobol_a checkerr.cbl
rem Compile the program.
cob2 -c -g -qpgmname(mixed) -qlib -I%DB2PATH%\include\cobol_a %1.cbl
 
rem Link the program.
ilink %1.obj checkerr.obj db2api.lib /ST:64000 /PM:VIO /NOI /DEBUG
 
goto exit
 
:error
echo Usage: bldapicb prog_name 
 
:exit
@echo on

Compile and Link Options for bldapicb

The command file contains the following compile options:

cob2
The IBM VisualAge COBOL compiler.
-c
Perform compile only; no link. This book assumes that compile and link are separate steps.
-g
Include debug information.
-qpgmname(mixed)
Instructs the compiler to permit CALLs to library entry points with mixed-case names.
-qlib
Instructs the compiler to process COPY statements.
-Ipath
Specify the location of the DB2 include files. For example: -I%DB2PATH%\include\cobol_a.

The command file contains the following link options:

ilink
Use the ilink linker to link edit.
checkerr.obj
Include the error-checking utility object file.
db2api.lib
Link with the DB2 library.
/ST:64000
Specify a stack size of at least 64000.
/PM:VIO
Enable the program to run in an OS/2 window.
/NOI
Do not ignore case when linking.
/DEBUG
Include debugging information.

Refer to your compiler documentation for additional compiler options.

To build the sample program client.cbl , enter:

   bldapicb client

The result is an executable file client. You can run the executable file against the SAMPLE database by entering the executable name:

   client

Embedded SQL Applications

The command file bldibmcb.cmd, in %DB2PATH%\samples\cobol, contains the commands to build an embedded SQL program.

The first parameter, %1, specifies the name of your source file. The second parameter, %2, specifies the name of the database to which you want to connect. Parameter %3 specifies the user ID for the database, and %4 specifies the password. Only the first parameter, the source file name, is required. Database name, user ID, and password are optional. If no database name is supplied, the program uses the default sample database.

@echo off
rem bldibmcb command file
rem Builds a COBOL program that contains embedded SQL
rem Usage: bldibmcb <prog_name> [ <db_name> [ < userid> <password> ]]
 
rem Connect to a database.
if "%1" == "" goto error
if "%2" == "" goto case1
if "%3" == "" goto case2
if "%4" == "" goto error
goto case3
:case1
   db2 connect to sample
   goto continue
:case2
   db2 connect to %2
   goto continue
:case3
   db2 connect to %2 user %3 using %4
   goto continue
:continue
 
rem Precompile the program.
db2 prep %1.sqb bindfile target ibmcob
 
rem Compile the checkerr error checking utility.
cob2 -c -g -qpgmname(mixed) -qlib -I%DB2PATH%\include\cobol_a checkerr.cbl
 
rem Compile the program.
cob2 -c -g -qpgmname(mixed) -qlib -I%DB2PATH%\include\cobol_a %1.cbl
 
rem Link the program.
ilink %1.obj checkerr.obj db2api.lib /ST:64000 /PM:VIO /NOI /DEBUG
 
rem Bind the program to the database.
db2 bind %1.bnd
 
rem Disconnect from the database.
db2 connect reset
 
goto exit
 
:error
echo Usage: bldibmcb <prog_name> [ <db_name> [ < userid> <password> ]]
 
:exit
@echo on

Compile and Link Options for bldibmcb

The command file contains the following compile options:

cob2
The IBM VisualAge COBOL compiler.
-c
Perform compile only; no link. This book assumes that compile and link are separate steps.
-g
Include debug information.
-qpgmname(mixed)
Instructs the compiler to permit CALLs to library entry points with mixed-case names.
-qlib
Instructs the compiler to process COPY statements.
-Ipath
Specify the location of the DB2 include files. For example: -I%DB2PATH%\include\cobol_a.

The command file contains the following link options:

ilink
Use the ilink linker to link edit.
checkerr.obj
Include the error-checking utility object file.
db2api.lib
Link with the DB2 library.
/ST:64000
Specify a stack size of at least 64000.
/PM:VIO
Enable the program to run in an OS/2 window.
/NOI
Do not ignore case when linking.
/DEBUG
Include debugging information.

Refer to your compiler documentation for additional compiler options.

To build the sample program updat, from the source file updat.sqb , enter:

 
   bldibmcb updat

The result is an executable file, updat. You can run the executable file against the sample database by entering the executable name:

   updat

Embedded SQL Stored Procedures

The command file bldicobs, in %DB2PATH%\samples\cobol, contains the commands to build a stored procedure. The command file compiles the stored procedure into a DLL on the server.

The first parameter, %1, specifies the name of your source file. The second parameter, %2, specifies the name of the database to which you want to connect. Parameter %3 specifies the user ID for the database, and %4 specifies the password. Only the first parameter, the source file name, is required. Database name, user ID, and password are optional. If no database name is supplied, the program uses the default sample database.

The command file uses the source file name, %1, for the DLL name.

@echo off
rem bldicobs command file
rem Builds a COBOL stored procedure
rem Usage: bldicobs <prog_name> [ <db_name> [ < userid> <password> ]]
 
rem Connect to a database.
if "%1" == "" goto error
if "%2" == "" goto case1
if "%3" == "" goto case2
if "%4" == "" goto error
goto case3
:case1
   db2 connect to sample
   goto continue
:case2
   db2 connect to %2
   goto continue
:case3
   db2 connect to %2 user %3 using %4
   goto continue
:continue
 
rem Precompile the program.
db2 prep %1.sqb bindfile target ibmcob
 
rem Compile the program.
cob2 -c -g -qpgmname(mixed) -qlib -I%DB2PATH%\include\cobol_a %1.cbl
 
rem Link the program.
ilink %1.obj checkerr.obj %1.def db2api.lib /ST:64000 /PM:VIO /NOI /DEBUG
 
rem Bind the program to the database.
db2 bind %1.bnd
 
rem Disconnect from the database.
db2 connect reset
 
rem Copy stored procedure to the %DB2PATH%\function directory.
rem Substitute the path where DB2 is installed for %DB2PATH%.
copy %1.dll %DB2PATH%\function
 
goto exit
 
:error
echo Usage: bldicobs <prog_name> [ <db_name> [ < userid> <password> ]]
 
:exit
@echo on

Compile and Link Options for bldicobs

The command file contains the following compile options:

cob2
The IBM VisualAge COBOL compiler.
-c
Perform compile only; no link. This book assumes that compile and link are separate steps.
-g
Include debug information.
-qpgmname(mixed)
Instructs the compiler to permit CALLs to library entry points with mixed-case names.
-qlib
Instructs the compiler to process COPY statements.
-Ipath
Specify the location of the DB2 include files. For example: -I%DB2PATH%\include\cobol_a.

The command file contains the following link options:

ilink
Use the ilink linker to link edit.
checkerr.obj
Include the error-checking utility object file.
%1.def
Module definition file.
db2api.lib
Link with the DB2 library.
/ST:64000
Specify a stack size of at least 64000.
/PM:VIO
Enable the program to run in an OS/2 window.
/NOI
Do not ignore case when linking.
/DEBUG
Include debugging information.

Refer to your compiler documentation for additional compiler options.

To build the outsrv stored procedure, from the source file outsrv.sqb , enter:

   bldicobs outsrv

The command file uses the module definition file, outsrv.def, contained in the same directory as the sample programs, to build the stored procedure. The command file copies the stored procedure DLL, outsrv.dll, on the server in the path %DB2PATH%\function. For DB2DARI parameter style stored procedures where the invoked procedure matches the name of the stored procedure DLL, this location indicates that the stored procedure is fenced. If you want this type of stored procedure to be unfenced, you must move the DLL to the %DB2PATH%\function\unfenced directory. For all other types of DB2 stored procedures, you indicate whether it is fenced or not fenced with the CREATE FUNCTION statement in the calling program. For a full discussion on creating and using the different types of DB2 stored procedures, please see the "Stored Procedures" chapter in the Application Development Guide.
Note:An unfenced stored procedure runs in the same address space as the database manager and results in increased performance when compared to a fenced stored procedure, which runs in an address space isolated from the database manager. With unfenced stored procedures there is a danger that user code could accidentally or maliciously damage the database control structures. Therefore, you should only run unfenced stored procedures when you need to maximize the performance benefits. Ensure these programs are thoroughly tested before running them as unfenced. Refer to the Application Development Guide for more information.

Once you build the stored procedure, outsrv, you can build the client application, outcli , that calls the stored procedure. You can build outcli using the command file bldibmcb. Refer to "Embedded SQL Applications" for details.

To access the stored procedure, run the sample client application by entering:

   outcli

The client application passes a variable to the server program, outsrv, which gives it a value and then returns the variable to the client application.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]