Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.20 Sample 19: Object Persistence (Indexed File)

Sample 19 demonstrates object persistence based on the program created in Sample 18, “Advanced Object-Oriented Programming.” In Sample 18, all objects are created in memory and thus upon termination of the program, all objects are lost.

In an actual system, however, data must be preserved when the program terminates. For an object-oriented system, in which the data is held in objects, the objects must continue to exist whether or not the application is executing. These objects are known as persistent objects.

In general, a persistent object can be implemented by relating the object to databases or files. In this example, persistent objects are rolled out by relating each object to an index file record.

For further details on object perpetuation, refer to the section “Making Objects Persistent” in the “NetCOBOL User’s Guide”.

Overview

The function of this sample is identical to that of Sample 18 except that the employee and address objects are stored in an index file, and persistence functions are added.

Persistence is implemented by adding the following methods to the employee and address objects.

Actually, the object saving and retrieving is implemented by using the employee master class and the address master class. From the object user (the MAIN program in this example), however, the process is viewed as if the employee object assumed all the tasks.

Programs and Files in Sample 19

COBOL Functions used in Sample 19

Object-Oriented Syntax used in Sample 19

Building the Application

Project Manager's build function is used to make the executable program.

  1. Start the Project Manager.

  2. Open project file SAMPLE19.PRJ.

  3. Select Build from the Project menu.

Debugging the Application

The project file is supplied with the debugging option set. You can execute the program under the control of the COBOL Debugger by:

  1. Selecting Debug from the Project menu.

  2. Clicking on the OK button in the Start Debugging dialog box.

    The COBOL Debugger loads the code as shown in the following figure.

Executing the Application

To run the application, select Execute from the Project menu.

The main application window is displayed.

For details on running the program, see Sample 18, ”Advanced Object-oriented Programming”. The main difference is that data you enter is preserved from one execution of the application to the next to the next.