Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.19 Sample 18: Advanced Object-Oriented Programming

Sample 18 uses all object-oriented specific functions including encapsulation, inheritance and polymorphism.

This program, which deals with two or more employee objects, uses the Dict class created in Sample 16, “Collection Class (Class Library).”

Overview

The application shows how an OO system can be set up to manage employee information. It implements, in a basic manner, the functions of registering, deleting, and modifying employee details, calculating salaries and printing a directory of employee information.

The employees are classified into staff members and managers. Different data is maintained and the pay calculation method differs between staff members and managers. The elements of the application are:

The staff member and manager classes inherit the employee class.

The addresses portion of the employee information is managed by an independent class (Address-Class).

Address objects are referenced from employee objects (and their subclasses).

The employee object defines the employee data to be managed by the supervisor.

Sample 18 use the dictionary class (Dict) created in Sample 16, “Collection Class (Class Library)”. It registers an employee object with the dictionary using the employee number as the key. The dictionary class allows easy repeat processing of two or more employee objects, and easy retrieval of an employee object.

Programs and Files in Sample 18

COBOL Functions used in Sample 18

Object-Oriented Syntax used in Sample 18

Building the Application

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

  1. Start the Project Manager.

  2. Open project file SAMPLE18.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:

To operate the program, enter the number of the desired process into “Select number” and press ENTER.

Note that this sample does not implement object persistence so data is lost when the application terminates. See Sample 19 for the same application with persistence added.


Registering Employee Information

Enter the employee information including:

For a manager, type in the special allowances (numeric character string of six or fewer digits). For a general staff member, type in the overtime (numeric character string of five or fewer digits).

Press the F3 key to register the data.

To terminate processing of employee registration information, press the F2 key.


Deleting Employee Information

To delete employee information, type in the employee number (four-digit numeric character string), and press the F3 key.

The employee data is displayed and can be corrected.


Calculating Employee Pay

When you select the “Salary calculation” function, the pay of all employees is calculated.

Entering an employee number and pressing the F3 key displays the pay information for that employee.

To terminate processing of the salary calculation function, press the F2 key.


Address list

An employee address list can be printed. Select Manager (1) or General employee (2), and then press the F3 key.


End

Terminates processing.