Inside COBOL #67 (COBOL 2000)
Shawn Gordon
The Kompany

Well this should tell you what I do in my spare time. I printed out a copy of the latest ANSI draft for COBOL, currently called COBOL 2000 (but we won’t see it till 2001 or 2002). The draft weighs in at a hefty 840 pages and has to be some of the most truly dry writing I have ever seen, but I guess it wasn’t written to be interesting.

My biggest challenge in going through the standard is that HP has such a minimal COBOL implementation that I wasn’t sure what was new and what was stuff the HP just didn’t do. Since all the object oriented stuff is definitely new, I’m going to focus on that for now, except for one really nifty thing I noticed.

You can now have dynamic tables so when you specify OCCURS ‘n’ TIMES, you don’t have to specify an upper bound on the table size, this is like doing a ‘malloc’ in C. There is a new function that was also added to tell you how many occurrences exist, so you can say:


This will return an integer to TABLE-MAX that is equal to the number of table entries currently used. Oh yea, you can now sort a table without writing it to a file (totally cool). There appears to be a number of new functions that have been added, I will cover them another time. Ok, on to the object oriented stuff.

For those of you familiar with object oriented programming lingo, the new COBOL will support the following object oriented features:

* Classes, Class Objects (‘Factories’), Methods
* Explicit and implicit invocation
* Inheritance: class inheritance and interface inheritance
* Multiple inheritance
* Properties
* Parameterized Classes
* Polymorphism
* COBOL Base Class

The COBOL syntax for a class definition uses a similar concepts as the concept of Nested Programs,
introduced in the COBOL 85 standard. The class itself has the role of the outermost program, factory and object definitions are nested inside the class definition, and method definitions in turn nested in the factory and object definitions.

Id Division.
Class-Id. class-name-1 Inherits class-name-2 ... .
Environment Division.
Configuration Section.
     Class class-name-3 as "external-class-name-3"
     Id Division.
     Environment Division.
     Data Division.
     Working-Storage Section.
     Procedure Division.
          {class methods}
     End Factory.
     Id Division.
     Environment Division.
     Data Division.
     Procedure Division.
          {object methods}
     End Object.
End Class class-name-1.
     Example 1. Class Definition

Id Division.
Method-Id. method-name-1 ...
Data Division.
Working-Storage Section.
Linkage Section.
Procedure Division [Using ...] [Returning ...] .
     Invoke object-reference method [Using ...] [Returning ...]
Exit method.
End Method method-name-1.
Example 2. Method Definition

Class Definition
· Format:
     [ ID DIVISION] (parameterized classes not covered here, see below)
   CLASS-ID. class-name-1 [ AS literal-1 ]
        INHERITS { class-name-2 … }.
             [ { CLASS class-name-3 [ AS "external-class-name-3" ] … ] .
             [ { INTERFACE int-name-1 [ AS "external-int-name-1" ] … ] .
         [ { factory definition } ]
    { object definition }
END CLASS class-name-1.
Factory Definition
· The factory object contains data and methods associated with the class, for example for creating
· Each class has only one factory object
· Environment Division contains only Input-Output Section
· Factory data and methods are accessible from all object methods of that class
· defined by:
FACTORY [IMPLEMENTS interface-name-1].
[Factory Environment Division ]
[Factory Data Division]
[{factory methods}…]]
· IMPLEMENTS clause indicates that the interface of this factory object conforms to interface-1 

Object Definition
· The object definition contains data and methods associated with the objects, i.e. the instances of the class
· Environment Division contains only Input-Output Section.
· Defined by:
OBJECT [IMPLEMENTS interface-name-1].
[Object Environment Division ]
[Object Data Division]
[{object methods}...]]
· IMPLEMENTS clause indicates that the interface of this object conforms to interface-1 

Method Definition
· Method definitions are contained in the Procedure Division of the Factory or the Object
· The method definition contains object procedures and data associated with the methods.
· Defined by:
            | method-name-1 [AS literal-1]         |
METHOD-ID.  ||GET|                                 |  [OVERRIDE]
            ||SET| PROPERTY property-name-1        |
[Method Environment Division]
[Method Data Division]
                     [RETURNING data-name-2].
END METHOD method-name-1.
· Property 
- property method
· Override
- overrides inherited method

This just touches the surface of how to start doing all this OO stuff. From what I can tell the new COBOL is much more like SmallTalk (supposedly the “purest” object oriented language) as opposed to C++ (sometimes referred to as a disgusting hybrid). I’ve never used SmallTalk, but I have used C++, and the new COBOL appears to be cleaner (in my opinion) than C++ in it’s implementation, but it’s been a few years.

On a slightly related topic, I try to stay on top of the GNU2COBOL project, which is supposed to be a COBOL compiler from GNU that has been slowly worked on for a number of years now. The folks that are writing it are constantly coming to COBOL users and asking their interpretation of various things in the COBOL standard. This is because of the rather vague wording that is used throughout the standards that are published. This of course is the problem when COBOL makers go to make their COBOL.

Well it appears that the new standard is going to provide material for a number of columns, so look forward to a few months of this stuff.