Henry is a senior application-development programmer at IBM. He is the lead designer and an architect of the mainframe IBM VS Cobol II and COBOL/370, and is presently a participant in the X3J4 Cobol committee. He can be contacted at IBM's Software Solutions Division, Santa Teresa Laboratory, San Jose, CA. Ann is a senior programmer in the COBOL Solutions area of IBM's Software Solutions Division, Santa Teresa Lab, San Jose, CA. She is an active member of X3J4 and the chairperson of the international Cobol working group.
If you think that Cobol is a language for days past, consider that, according to the Datapro Information Services Group, an estimated 150 billion lines of Cobol source code are at work in mission-critical business applications worldwide, and programmers add about five billion lines each year. Likewise, International Data Corp. reports that revenues for Cobol desktop development are expected to increase to $176.4 million by 1998, up from $86.3 million in 1993. These figures indicate a solid average growth rate of about 15.4 percent a year. In medium-size and large U.S. companies, 42.7 percent of all applications-development staffs use Cobol. Thirty-five percent of such companies report that the language is used for more than two-thirds of their applications.
While languages such as C++ and Smalltalk garner the lion's share of attention from the object-oriented community, Cobol has also been making object-oriented strides. In particular, a proposed revision of the Cobol standard includes object-oriented extensions. The draft standard is being developed jointly by the International Organization for Standardization (ISO) and Accredited Standards Committee X3 (ASC X3), the latter operating under the procedures of the American National Standards Institute (ANSI). The target date for completion of the proposed standard is 1997.
While we will focus in this article on the object-oriented extensions to Cobol, we will also highlight other features proposed in the draft.
Cobol's early acceptance can be traced to the fact that it was the first stable, portable business language. Since the language was conceived in 1959 by the Conference on Data Systems Languages (CODASYL), committees have continually refined and improved it, incorporating innovative programming methods. CODASYL, ANSI, and ISO have regularly published the agreed-upon standards emerging from these committees.
With the incorporation of structured programming, the 1985 standard (ANSI X3.23-1985) introduced major enhancements to Cobol. Structured-programming concepts were part of a movement in programming methodology toward replacing unwieldy, multibranching "spaghetti" code with a more tightly controlled flow of logic. As part of Cobol, it gave users more readable and maintainable programs.
Standardization has given Cobol a high degree of reliability and portability. From the beginning, programmers wanted Cobol to be a robust language that they could use on any platform or computer. This need expanded as multiplatform installations became more common in the 1980s. Vendors met the challenge by making standard-compliant implementations of Cobol available on many platforms and systems, including mainframe and midrange computers, DOS, UNIX, Windows, and OS/2. (IBM, for example, uses the same Cobol compiler technology on MVS, VM, VSE, AIX, and OS/2.)
Today, the 1985 Cobol standard is widely accepted, and most industry and government organizations rely on adherence to it. In order to bid on government jobs, for instance, Cobol implementations must conform to the Federal Information Processing Standard for Cobol (FIPS 21-4), which is based on Cobol standards.
The draft 1997 proposal for Cobol incorporates the basic object-oriented programming capabilities found in C++ and Smalltalk (see Table 1): inheritance, which allows objects to inherit data and behaviors from other objects; polymorphism, which simplifies coding by letting programmers use a single interface to access objects of different classes; and encapsulation, which hides the implementation of data and methods from clients (user code), thereby protecting clients from the effects of implementation change.
However, object-oriented extensions are just one piece of the new standard. It also includes a common method of handling exceptions, to facilitate error discovery; an option for increased portability of arithmetic, which lends consistency and portability to certain computations: bit-string handling, to allow manipulation of bits of data; compiler directives, for portable specification of processing options; automatically expanded tables; dynamic file allocation; and support for large character sets (for applications that use data in languages other than English).
The schedule for the new standard depends, among other factors, on the changes vendors and users request during the review processes. A draft of the proposed 1997 standard underwent informal public review in spring of 1995, and the resulting comments are presently being considered for incorporation into the draft. A formal public review will take place in early 1996.
Meanwhile, the draft 1997 standard is generating interest among vendors. Hitachi, IBM, Ryan-McFarland, and Micro Focus have already incorporated subsets, or partial implementations, of the object-oriented programming proposals into their Cobol products, and IBM is committed to supporting the final adopted standard.
To ease the transition to object orientation, the committees are keeping the standard as close as possible to Cobol 85. The fundamental elements are classes, methods, interfaces, inheritance, and a few standard system classes. A class defines the layout of object instance data and the methods for accessing the data; see Example 1. The code for a method follows the form of a program; see Example 2.
The idea is to add just enough features to make Cobol a rich, object-oriented model, while allowing Cobol shops and their existing skills to transition easily into the object-oriented environment.
Cobol provides basic classes with methods for creating and initializing objects (Base class); and saving, retrieving, and deleting persistent objects (System-Object class).
Vendors are looking at other emerging standards in order to maximize object-oriented Cobol's portability and flexibility in a client/server environment, such as the Object Management Group (OMG) Common Object Request Broker Architecture (CORBA). IBM's object-oriented Cobol is based on its System Object Model (SOM), which implements CORBA. IBM's direct-to-SOM object-oriented Cobol compiler enables programmers to sidestep learning the SOM Interface Definition Language (IDL). The distributed features of SOM/DSOM let applications access objects across multiple systems, enabling users to create client/server applications with object-oriented Cobol.
Listing One is a simple banking application written in IBM Cobol. Listing One defines an Account with four methods: OpenAccount, Balance, Deposit, and Withdraw. Account uses the INHERIT keyword to derive from SomObject. Listing One also creates SavingAccount, a subclass of Account, which shows how to use the OVERRIDE keyword to override methods inherited from the parent class. In this case, SavingAccount overrides the Deposit and Withdraw methods. SavingAccount also introduces one new method, GetInterest. Finally, Listing One shows how these methods can be invoked from a client program.
Cobol's cautious evolution has allowed it to incorporate inventive software-development technologies at a pace that protects its integrity and stability. And with recent object-oriented language extensions and the availability of visual programming tools, Cobol has become a robust tool for object-oriented application development.
For information on obtaining future U.S. review copies of the draft Cobol standard, contact Don Schricker, Chairman, Technical Committee X3J4 at das@mfltd.co.uk. For details on future international reviews, contact Ann Wallace, Convenor, IS0/IEC JTC1/SC22/WG4-Cobol at AnnWallace@vnet.ibm.com.
The Desktop 3GL Market: Review and Forecast, 1993-1998. Framingham, MA: International Data Corp., December 1994.
IBM World Wide Web. URL http://www.torolab.ibm.com/software/ad/ad3gl.html.
FAQ on Cobol. Micro Focus World Wide Web. URL http://www.mfltd.co.uk/FAQ/cobol-faq.html.
Internet Usenet Newsgroup: comp.lang.cobol.
Kain, Brad. "Distributed Architecture is Mission of OMG." Application Development Trends (August 1994).
McClure, Steve. Object Technology into the Mainstream: The Adoption and Assimilation of Object Technologies by the MIS Community in the United States. Framingham, MA: International Data Corp., September 1994.
Obin, Raymond. Object-Orientation: An Introduction for Cobol Programmers. Palo Alto, CA: Micro Focus Press, 1993.
Example 1: Defining a BankAccount class in Cobol. BankAccount inherits from the standard Cobol system class Base. *> BankAccount object
END METHOD Create-BankAccount.
END OBJECT.
END CLASS BankAccount.
Copyright © 1995, Dr. Dobb's Journal
CLASS-ID. BankAccount INHERITS Base.
OBJECT.
DATA DIVISION.
*> instance data for BankAccount objects
METHOD-ID. Create-BankAccount.
*> code for a method to create a
Example 2: Defining a Cobol method. The INVOKE statement acts like the call statement in Cobol 85. The name of the method and the parameters on the procedure division statement define the interface for the method.
METHOD-ID. Create-BankAccount.
DATA DIVISION.
LINKAGE SECTION.
01 New-Account OBJECT REFERENCE BankAccount.
PROCEDURE DIVISION USING New-Account.
INVOKE SELF "new" RETURNING New-Account.
END METHOD Create-BankAccount.
Table 1: Comparing object-oriented language features.
Feature Smalltalk C++ Cobol
Pure object orientation Yes Hybrid Hybrid
Inheritance Single Multiple Multiple
Encapsulation Total Limited Total
Polymorphism Yes Yes Yes
Classes as objects Yes No Yes
Type checking No Yes Yes
Class libraries Excellent Good Limited
Persistent objects Yes No Simple
Listing One
ACCOUNT CLASS DEFINITION
IDENTIFICATION DIVISION.
CLASS-ID. Account INHERITS SomObject.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY. | Linkage to
CLASS SomObject is "SomObject" | SOM Interface
CLASS Customer. | Repository
DATA DIVISION.
WORKING-STORAGE SECTION.
01 AccountNumber PIC 9(8) USAGE BINARY. | Instance
01 CustomerObject USAGE OBJECT REFERENCE Customer. | Data
01 AccountBalance PIC 9(9)V99 VALUE ZERO. | or
01 AccountType PIC X(10). | Object Data
PROCEDURE DIVISION.
IDENTIFICATION DIVISION. | OpenAccount
METHOD-ID. OpenAccount. |
DATA DIVISION. | Method
LINKAGE SECTION. | Definition
01 CustObj USAGE IS OBJECT REFERENCE Customer. |
01 AccNum PIC 9(8) USAGE IS BINARY. |
PROCEDURE DIVISION USING CustObj AccNum. |
SET CustomerObject TO CustObj |
MOVE AccNum TO AccountNumber. |
END METHOD OpenAccount.
IDENTIFICATION DIVISION. | Balance
METHOD-ID. Balance. | Account
DATA DIVISION. | Method
LINKAGE SECTION. | Definition
01 AccBal PIC 9(9)V99. |
PROCEDURE DIVISION RETURNING AccBal. |
MOVE AccountBalance TO AccBal. |
END METHOD Balance.
IDENTIFICATION DIVISION. | Deposit
METHOD-ID. Deposit. | Account
DATA DIVISION. | Method
LINKAGE SECTION. | Definition
01 DepositAmount PIC 9(9)V99. |
01 NewBalance PIC 9(9)V99. |
PROCEDURE DIVISION USING DepositAmount RETURNING NewBalance.
ADD DepositAmount TO AccountBalance |
MOVE AccountBalance TO NewBalance. |
END METHOD Deposit.
IDENTIFICATION DIVISION. | Withdraw
METHOD-ID. Withdraw. | Account
DATA DIVISION. | Method
LINKAGE SECTION. | Definition
01 TransAmount PIC 9(9)V99. |
01 NewBalance PIC 9(9)V99. |
PROCEDURE DIVISION USING TransAmount RETURNING NewBalance.
SUBTRACT TransAmount FROM AccountBalance |
MOVE AccountBalance TO NewBalance. |
END METHOD Withdraw.
END CLASS Account.
SUBCLASS OF THE ACCOUNT CLASS DEFINITION
(SAVINGS ACCOUNT)
IDENTIFICATION DIVISION.
CLASS-ID. SavingAccount INHERITS Account.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS Account is "Account".
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WithdrawPerDay PIC S9(8) USAGE BINARY. | Instance and
01 MinBalance PIC 9(9)V99 VALUE 250. | Object Data
01 MinDeposit PIC 9(9)V99 VALUE 100. |
01 InterestRate PIC 9V99 VALUE 0.05. |
PROCEDURE DIVISION.
IDENTIFICATION DIVISION.
METHOD-ID. Deposit IS METHOD OVERRIDE. | Override of the
DATA DIVISION. | Original Deposit
WORKING-STORAGE SECTION. | Method
01 PenaltyAmount PIC 9(9)V99 VALUE 10.
LINKAGE SECTION.
01 DepositAmount PIC 9(9)V99.
01 NewBalance PIC 9(9)V99.
PROCEDURE DIVISION USING DepositAmount RETURNING NewBalance.
IF DepositAmount LESS THAN MinDeposit THEN
* SELF and SUPER refer to the current object.
INVOKE SELF "Withdraw" USING PenaltyAmount RETURNING NewBalance.
END METHOD Deposit.
IDENTIFICATION DIVISION.
METHOD-ID. Withdraw IS METHOD OVERRIDE. | Override of the
DATA DIVISION. | Original Withdraw
LINKAGE SECTION. | Method
01 TransAmount PIC 9(9)V99.
01 NewBalance PIC 9(9)V99.
PROCEDURE DIVISION USING TransAmount RETURNING NewBalance.
INVOKE SELF "Balance" RETURNING NewBalance.
IF NewBalance - TransAmount IS GREATER THAN MinBalance THEN
INVOKE SUPER "Withdraw" USING TransAmount RETURNING NEWBalance.
ELSE
DISPLAY "Transaction was not performed for lack of funds".
END METHOD Withdraw.
IDENTIFICATION DIVISION.
METHOD-ID. GetInterest. | GetInterest Method
ENVIRONMENT DIVISION. | Definition
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NewBalance PIC 9(9)V99.
LINKAGE SECTION.
01 TransAmount PIC 9(9)V99.
01 InterestAmount PIC 9(9)V99.
PROCEDURE DIVISION RETURNING InterestAmount.
INVOKE SELF "Balance" RETURNING NewBalance.
MULTIPLY NewBalance BY InterestRate GIVING InterestAmount.
END METHOD GetInterest.
END CLASS SavingAccount.
CLIENT PROGRAM DEFINITION
This program is using the methods and classes defined above to
open a savings account.
IDENTIFICATION DIVISION
PROGRAM-ID. Client.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS Customer
CLASS SavingAccount IS "Bank-Saving-Account".
DATA DIVISION
WORKING STORAGE SECTION.
01 CustomerObj USAGE IS OBJECT REFERENCE Customer.
01 anAccount USAGE OBJECT REFERENCE SavingAccount.
01 AccountNum Pic 9(8).
01 DepositAmount Pic 9(9)V99.
01 NewAccountBalance Pic 9(9)V99.
PROCEDURE DIVISION.
INVOKE SavingAccount "somNew" RETURNING anAccount
INVOKE anAccount "OpenAccount" USING CustomerObj AccountNum
INVOKE anAccount "Deposit" USING DepositAmount
RETURNING NewAccount Balance.
END PROGRAM Client.
****************************