Channels ▼

Community Voices

Dr. Dobb's Bloggers

Cobol Comeback

August 19, 2008

 

Cobol, that much-maligned zombie of a programming language, simply refuses to die and has been back in the news of late--particularly in California where it made headlines for thwarting the governor's budget-cutting plans. Michael Swaine will have a little something to say on the subject in the next issue of DDJ--but until then, you can take a walk down Cobol's memory lane with this status report, written by IBM's Henry Saade and Ann Wallace for a 1995 issue of Dr. Dobb's Journal.

 

 

Cobol '97: A Status Report

Cobol gets object oriented

by Henry Saade and Ann Wallace



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.

Historically Speaking
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.

A New Standard
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.

Object-Oriented Extensions
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.

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.

****************************



Conclusion
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.

Bibliography
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.

 

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video