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:
Database
Products necessary for database access with ODBC
ODBC driver
ODBC driver manager
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:
Authorization processing
Stock check
Order registration
Order exact calculation
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
DB_ACCESS.COB (COBOL source file)
ONLINE_STORE.COB (COBOL source file)
STORESV1.PRJ (project file)
STORESV1.CBI (compiler option file)
STORESV1_DLL.CSI (COM server information file)
STORESV1.DEF (module definition file)
Applicable COBOL Functions
COM server function
Remote database access
*COM-ARRAY class
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.
CUSTOMER table
Use the format shown below to create this table.
USERID | PASSWORD |
---|---|
Variable-length character 32 bytes | Variable-length character 32 bytes |
Store the data items shown below in the client table.
USERID | PASSWORD |
---|---|
USER0001 USER0002 USER0003 USER0004 USER0005 USER0006 USER0007 USER0008 USER0009 USER0010 | USER0001 USER0002 USER0003 USER0004 USER0005 USER0006 USER0007 USER0008 USER0009 USER0010 |
STOCK table
Use the format shown below to create this table.
PRODUCTNUMBER | QUANTITY |
---|---|
Fixed-length character 10 bytes | Fixed-length character 10 digits |
Store the data items shown below in the stock table.
PRODUCTNUMBER | QUANTITY |
---|---|
FMV2TXH111 FMV2TXH161 FMV2TXH151 FMV2TXF111 FMV2TXF161 FMV2TXF151 FMV2DXH111 FMV2DXH161 FMV2DXH151 FMV2DXF111 FMV2DXF161 FMV2DXF151 FMV2DXD111 FMV2DXD161 FMV2DXD151 FMV2DXA111 FMV2DXA161 FMV2DXA151 FMV3NA3LC0 FMV3NA3LC6 | 900000 100000 500000 45000 300000 60000 90000 55000 990000 10000 777700 200000 690000 870000 619000 2900000 8760000 100000 10000 300 |
ORDERTABLE
Use the format shown below to create this table.
ORDERNUMBER | USERID | DATE |
---|---|---|
Fixed-length character 12 bytes | Variable-length character 32 bytes | Fixed-length character 14 bytes |
No data need be stored in the ORDERTABLE table.
ORDERDETAIL table
Use the format shown below to create this table.
ORDERNUMBER | PRODUCTNUMBER | QUANTITY |
---|---|---|
Fixed-length character 12 bytes | Fixed-length character 10 bytes | Decimal integer 10 digits |
No data need be stored in the ORDERDETAIL table.
- Use the ODBC information file setting tool (SQLODBCS.EXE) to create an ODBC information file (assumed to be C:\DBMSACS.INF).
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.
Start the Project Manager.
Open the project file SAMPLE25.PRJ.
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.
Select "Build" from the "Project" menu.
After build termination, check that STORESV1.DLL is created.
Setup the Server Program Execution Environment
Select "Run-time Environment Setup Tool" from the "Tools" menu of Project Manager.
The run-time environment setup tool is displayed.
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).
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).
Click the Apply button.
The data is saved in the object initialization file.
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.
When the COM server and COM client are used on the same machine
Use REGSVR32.EXE to register the COBOL application in the system registry.
For details, refer to Section the "Registering or Deleting a COM Server" in the "NetCOBOL User’s Guide".
When the COM server is used from a COM client in a remote network-connected machine.
Use Microsoft Transaction Server (MTS). Use MTS explorer to register the COBOL application in the system registry and MTS. For details, refer to Section the "Registration in the MTS Environment" in the "NetCOBOL User’s Guide".