Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.21 Sample 20: Object Persistence (Database)

Sample 20 demonstrates a method of making a permanent object and is based on the program created in "Sample 18 Object-Persistence". In sample 18, all objects were created in memory. Therefore, the objects disappear at program termination. However, some data has to remain in the system after the program ends. An object that retains data after the program ends is called a "Permanent Object".

In the previous program, such data was stored in a file or a database. To create a permanent object one must associate the permanent object with data in file or a database. In this example, the permanent object has been achieved by associating each object with a line in a data base table.

Refer to the "NetCOBOL User's Guide" for details on Object Persistence.

The database exists on the server, and is accessed from the client side.

The database is accessed via the ODBC driver. For information on setting up and using ODBC databases, please refer to the Chapter 19, "Database (SQL)" of the "NetCOBOL User's Guide".

The following products are necessary to execute this program.

Overview

The management of employee information (addition, deletion, and modification), the salary calculations, and address are printed as was done in sample 18.

In addition to the functions above, in this example the employee object and the address object stored in the database, and a permanent object function is added.

These functions have been created in the employee and the address objects by adding the following methods.

Available Programs

Applicable COBOL Functions

Available Object-oriented Statements/Paragraphs/Definitions

INVOKE and SET statements

Object property

In-line invocation of a method

Repository paragraph

Class definition, object definition, factory definition, and method definition

Prerequisite to Executing the Program

ODBC is a defined interface that attempts to provide a highly generic API into any database system that provides compliant drivers. Just about every database system available today provides ODBC drivers for a variety of platforms.

In order to proceed with this exercise, you must have already installed 32-bit ODBC support on your Windows 2000, XP, Windows Server 2003, or Windows Server 2008 system, along with the Microsoft Access Driver.


Verifying Whether ODBC is Installed

Please refer to "Sample11".


Defining an ODBC Source for Your Application

The first development task that needs to be accomplished is to define an ODBC Source for the application.

An ODBC Source can be thought of as simply specifying to the ODBC manager a symbolic name that you wish to use in your application to describe an ODBC connection to a specific ODBC database driver and database.

The following figures may or may not match what you see on your particular operating system, but you should be able to perform the following tasks by using the instructions provided.

Bring up the Administrative Tools and double click on the Data Sources (ODBC) icon.

The main ODBC Data Source Administrator window is displayed.


You will add a new User DSN. Select the User DSN tab, and click on the Add button.

ODBC Data Source Administrator displays the “Create New Data Source” dialog box.

Select the Microsoft Access Driver (*.mdb) and click on the Finish button.

The ODBC Microsoft Access Setup dialog box is displayed.

Enter Sample20 in the Data Source Name field and Sample20 Database in the Description field as shown above.

You also need to select a file (database) to bind this driver to. Click on the Select button in the ODBC Microsoft Access Setup dialog box. The Select Database dialog box is displayed. Navigate through the directories and find the "Sample20.mdb" database file:

Click on the OK button. This will take you back to the ODBC Microsoft Access Setup dialog box.

Click on the OK button. This will take you back to the main ODBC Source Administrator window.

Note that "Sample20" has been added to the list in User DSN. Although you should not set any additional options for this exercise, you may wish to highlight “Sample20” and click on the Configure button.

This will give you an idea of some of the additional options that are available when developing these types of applications. Once you are back to the main ODBC Source Administrator window, click on the OK button. This will exit the ODBC configuration facility. You have now defined the new ODBC Source (Sample20) you are going to use with COBOL.

Building/Rebuilding the Program

Project manager's build function is used to create the executable program.

  1. The project manager is started.

  2. Project file "SAMPLE20.PRJ" is opened.

"Build" is selected from the "Project" menu.

Setup the Execution Environment Information

The initialization file for execution is updated with the Run-time Environment Setup Tool. The content is shown below.

  1. The Run-time Environment Setup Tool is started.

  2. The initialization file for execution is opened. (COBOL85.CBR)

  3. A common tab is selected.

  4. The ODBC information file name is specified for @ODBC_Inf. (SAMPLE20.INF)

  5. The key definition file name is specified for @CBR_SCR_KEYDEFFILE. (SAMPLE20.KBD)

  6. Click "Apply" button, and the content is saved in the execution initialization file.

  7. Click "Exit" button in file menu, and the Run-time Environment Setup Tool ends.

Executing the Program

To execute the program, "Execute" is selected from the project menu.

Execution Procedure

Please refer to "Sample 18 Object Persistence" for execution procedures.

However, please note the following points.