Building UNIX Micro Focus COBOL routines

Db2® database products provide build scripts for compiling and linking Micro Focus COBOL embedded SQL and Db2 API programs. These are located in the sqllib/samples/cobol_mf directory, along with sample programs that can be built with these files.

About this task

The script, bldrtn, contains the commands to build routines (stored procedures). The script compiles the routine source file into a shared library that can be called by a client application.

The first parameter, $1, specifies the name of your source file. The script uses the source file name for the shared library name. The second parameter, $2, specifies the name of the database to which you want to connect. Since the shared library must be built in 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.

Procedure

  1. Before building Micro Focus COBOL routines, you must run the following commands:
    db2stop
    db2set DB2LIBPATH=$LD_LIBRARY_PATH
    db2set DB2ENVLIST="COBDIR LD_LIBRARY_PATH"
    db2set
    db2start

    Ensure that db2stop stops the database. The last db2set command is issued to check your settings: make sure DB2LIBPATH and DB2ENVLIST are set correctly.

  2. To build the sample program outsrv from the source file outsrv.sqb, if connecting to the sample database, enter: bldrtn outsrv.
    If connecting to another database, also enter the database name. For example:
    bldrtn outsrv database
    The script file copies the shared library to the server in the path sqllib/function.

    Once you build the stored procedure outsrv, you can build the client application outcli that calls it. You can build outcli using the script file, bldapp.

  3. To call the stored procedure, 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 could be sample, or its alias, or another name.
    userid
    Is a valid user ID.
    password
    Is a valid password for the user ID.

    The client application accesses the shared library, outsrv, and executes the stored procedure function of the same name on the server database. The output is then returned to the client application.