Sample 28 demonstrates COBOL COM server program transaction management using the Microsoft(R) Transaction Server (MTS).
See Chapter 24 in the "NetCOBOL User’s Guide" for details on COBOL application transaction management using MTS.
To use this program, the following products are necessary:
One of the following products:
Microsoft(R) Windows(R) 2000 Server operating system
Microsoft(R) Windows(R) 2000 Advanced Server operating system
Microsoft(R) Windows Server(R) 2003 Standard Edition
Microsoft(R) Windows Server(R) 2003 Enterprise Edition
Microsoft(R) Windows Server(R) 2008 Standard Edition
Microsoft(R) Windows Server(R) 2008 Enterprise Edition
Microsoft(R) Transaction Server 2.0 or later
This program accesses a database via the ODBC driver, so the following products are necessary to run this program:
Database
Products necessary for database access with ODBC
ODBC driver
ODBC driver manager
For database access using an ODBC driver, refer to Chapter 19 in the "NetCOBOL User’s Guide".
Overview
As in Sample 25, this sample program provides the following functions for constructing an online store application:
Authorization processing
Stock check
Order registration
Order calculation
However, this program manages transactions directly from a COBOL program by using the MTS functions.
In Sample 25, the embedded SQL statements COMMIT/ROLLBACK are used and transaction management depends on the database. This is a simple approach for someone who is familiar with embedded SQL statements but increases the database processing load.
This program manages transactions by itself with MTS functions. This reduces the database processing load and enables more detailed transaction management.
There are two methods of using the MTS function for transaction management from a COBOL application:
Control of transactions where the object is operating from the COM server object
Control of transactions where the COM server is operating from the COM client
The first method is shown below.
Available Programs
DB_ACCESS.COB (COBOL source file)
ONLINE_STORE.COB (COBOL source file)
STORESV2.PRJ (project file)
STORESV2.CBI (compiler option file)
STORESV2_DLL.CSI (COM server information file)
STORESV2.DEF (module definition file)
Applicable COBOL Functions
COM server function
Remote database access
*COM-ARRAY class
Object context object
Applicable COBOL Statements
The IF, INVOKE, INITIALIZE, SET, MOVE, and PERFORM statements are used.
The embedded SQL statements (CONNECT, INSERT, SELECT, UPDATE, ROLLBACK, and DISCONNECT) are used.
Operations Necessary Before Execution
Construct an environment where a database can be accessed via the ODBC driver.
Set a default server to be connected to and create the five tables listed below in a database on the server. For the formats of the tables and data to be stored, see Sample 25, "Creating a COBOL COM Server Program “.
CUSTOMER table
STOCK table
ORDERTABLE table
ORDERDETAIL table
Use the ODBC information file 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.
In the screen snapshots below, it is assumed that NetCOBOL was installed in folder C:\NetCOBOL. Change the folder name C:\NetCOBOL to the name of the folder where NetCOBOL is installed on your machine.
Start the Project Manager.
Open the project file SAMPLE28.PRJ.
Check the COM server information.
Select a target file (STORESV2.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 SAMPLE28.DLL is created.
Registering the COBOL Application in MTS
The COBOL application must be registered in the Windows system to use it as a COM server. Also specify a transaction control method in the registration.
Use the MTS explorer to register the COBOL application in the system registry and MTS. For details, refer to the section "Registration in the MTS Environment" in the "NetCOBOL User’s Guide".
Setup the Server 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 (SAMPLE28.DLL).
Select the Common tab and enter data as shown below:
Specify an ODBC information file name in the environment variable @ODBC_Inf (ODBC information file specification).
Click the Apply button.
The data is saved in the object initialization file.
Select "Exit" on the "File" menu to exit the tool.
Modifying the Client Program
Samples 26 and 27 can be used as clients of this program by modifying them as shown below.
Using the COBOL client in Sample 26.
Modify the cluster specifier of the CLMAIN.COB repository as shown below.
000200 CLASS ONLINE_STORE AS "*COM:STORESV2:ONLINE_STORE"
Open the project file SAMPLE26.PRJ, delete COM server name STORESV1, and enter STORESV2.
Rebuild SAMPLE26.EXE.
Create an installation program for client information on the Sample 28 program and install it in the client.
Using the ASP client in Sample 27.
Modify the CreateObject argument for COM object creation as shown below.
Catalog.asp
Set OLSService = Server.CreateObject("STORESV2.ONLINE_STORE")
Confirm.asp
Set OLSService = Server.CreateObject("STORESV2.ONLINE_STORE")
Order.asp
Set obj = Server.CreateObject("STORESV2.ONLINE_STORE")