Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.26 Sample 25: Creating a COBOL COM Server Program

Sample 25 shows an example where the COBOL COM server function is used to enable a COBOL program to be used as a COM server.

The COBOL class definition can be shifted to the COM server without change, by using the COBOL COM server function. The selected class is published as the COM server interface simply by setting the necessary information with the Project Manager's COM sever creation function and executing rebuild.

For details on the COBOL COM function, refer to Chapter 24 in the "NetCOBOL User’s Guide".

This program accesses a database via an ODBC driver, so the following products are necessary to use this program:

For details of database access using an ODBC driver, refer to Chapter 19 in the "NetCOBOL User’s Guide".

Overview

The sample program consists of two class definitions.

The COBOL ONLINE_STORE class is the COM server class. The ONLINE_STORE class provides the following functions for constructing an online store application:

In addition to COBOL programs, programs generated with Visual C++(R), programs generated with Visual Basic(R), and active server pages (ASP) Visual Basic(R) Scripting Edition (VBScript) can be used as client programs to use these functions. See Sample 26 and Sample 27 for examples of the COBOL client and ASP client.

Available Programs

Applicable COBOL Functions

Applicable COBOL Statements

The IF, INVOKE, INITIALIZE, SET, MOVE, and PERFORM statements are used.

The embedded SQL statements (COMMIT, CONNECT, INSERT, SELECT, UPDATE, ROLLBACK, and DISCONNECT) are used.

Operation necessary before executing the program

Construct an environment where a database can be accessed via the ODBC driver.

Set a default server to be connected and create the four tables shown below in a database on the server.

Building and Rebuilding

The Project Manager's Build function is used to compile and link this program.

Folder C:\NetCOBOL is assumed below as the location where NetCOBOL is installed.

Change the folder name C:\NetCOBOL to the name of the folder where NetCOBOL is installed.

  1. Start the Project Manager.

  2. Open the project file SAMPLE25.PRJ.

  3. Check the set COM server information.

    Select a target file (STORESV1.DLL) and select "View" from the "Project-Option-COM server" menu.

    The "View" dialog is opened and the server information can be referenced.

  4. Select "Build" from the "Project" menu.

    After build termination, check that STORESV1.DLL is created.

Setup the Server Program Execution Environment

  1. Select "Run-time Environment Setup Tool" from the "Tools" menu of Project Manager.

    The run-time environment setup tool is displayed.

  2. Select "Open" on the "File" menu and create an object initialization file (COBOL85.CBR) in the folder that contains the dynamic link library (STORESV1.DLL).

  3. Select a common tab and set data as shown below:

    • Specify an ODBC information file name in environment variable information

      @ODBC_Inf (ODBC information file specification).

  4. Click the Apply button.

    The data is saved in the object initialization file.

  5. Select File, Exit to terminate the run-time environment setup tool.

Registering the COM Server

The created COBOL application must be registered in the Windows system to use it as a COM server. There are two registration methods depending on how the COM server is used.