COBOL
2000
By Shawn M.
Gordon
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 wont
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 wasnt written to be interesting.
My biggest
challenge in going through the standard is that HP has such a minimal
COBOL implementation that I wasnt sure what was new and what
was stuff the HP just didnt do. Since all the object-oriented
stuff is definitely new, Im 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
dont 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:
MOVE FUNCTION
ALLOCATED-OCCURRENCES (MY-TABLE) TO TABLE-MAX
This will return
an integer to TABLE-MAX that is equal to the number of table entries
currently used. Oh yeah 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. Okay, 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 1
The COBOL syntax
for a class definition uses a concept similar to 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 are in turn nested in the factory and object
definitions.
Id Division.
Class-Id. class-name-1
Inherits class-name-2 ... .
...
Environment Division.
Configuration Section.
Repository.
Class class-name-3 as
external-class-name-3
...
Id Division.
Factory.
Environment Division.
...
Data Division.
Working-Storage Section.
...
Procedure Division.
{class methods}
End Factory.
Id Division.
Object.
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 }.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
[ { 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 objects
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:
[ID DIVISION.]
FACTORY [IMPLEMENTS
interface-name-1].
[Factory Environment Division ]
[Factory Data Division]
[PROCEDURE DIVISION.
[{factory methods}]]
END FACTORY.
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:
[ID DIVISION.]
OBJECT [IMPLEMENTS
interface-name-1].
[Object Environment Division ]
[Object Data Division]
[PROCEDURE DIVISION.
[{object methods}...]]
END OBJECT.
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:
[ID DIVISION.]
| method-name-1 [AS literal-1] |
METHOD-ID. ||GET| | [OVERRIDE]
||SET| PROPERTY property-name-1 |
[Method Environment Division]
[Method Data Division]
[PROCEDURE DIVISION [USING
data-name-1}...]
[RETURNING data-name-2].
{statements}...]
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). Ive never used SmallTalk, but I have used
C++, and the new COBOL appears to be cleaner (in my opinion) than C++
in its implementation, but its 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 for 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.
It appears that
the new standard is going to provide material for more than one
column, so look forward to a few months of this topic.
Shawn Gordon,
whose S.M. Gordon & Associates firm supplies HP 3000 utilities,
has worked with 3000s since 1983.
Copyright The
3000 NewsWire. All rights reserved.
|