COBOL TIPS #28
by
Shawn M. Gordon
President S.M.Gordon & Associates

Well I am back from my first break from this column in over 2 years. The hundreds, if not thousands of phone call’s., letters and email’s, convinced me that I needed to keep this column going no matter what. Well, actually there was about 7 or 8 people who wondered what happened, but they were very enthusiastic.

I’ve got to tell you, I think I am getting blisters on my brain from all the different information I have been trying to absorb lately. If you are to read the weekly trade magazines you are either really excited, or standing over the sink with a razor on your wrist. Heck, by the time you read this (probably July), things will be even more different than they are now (March). All of this Internet, and JAVA, and VBScript, etc, etc, etc, is really a lot to think about. Don’t worry, I am leading up to something.

Although I didn’t attend IPROF, I understand that Alfredo Rego of Adager fame proposed a “contest” to create a mechanism for JAVA to access IMAGE intrinsics directly through the implementation of high level “classes” that handled all the IP headaches. His point isn’t necessarily so that a web page can read an Image data base, but so that we can IP enable applications on the 3000 for distributed processing. This has some fascinating implications, and HP really should be at the front of doing something like this, they should have the JAVA virtual machine ported to the 3000, and be on top of this, but if Alfredo and his infinite optimisum has any say, it will get done regardless.

I have had several interesting ideas on being able to port existing applications to web enabled servers with a very minimal amount of work, if I get farther on this project I will fill you in.

So anyway, with all this rash of “stuff” going on, I managed to get on the beta list of the MicroFocus Visual Object Cobol product. The version I have should be the last beta, so the production will be out by the time you read this. So this month I thought I would introduce just a bit more on this emerging topic.

First we have an overview of how a CLASS is implemented in VOC

CLASS-ID.  BankAccount

+----------------------------------------+
| Class Initialzation Code               |
|      --------------                    |
|  Class Object                          |
|     --------------                     |
|  Class Data                            |
|     --------------                     |
| Class Method  "new"                    |
+----------------------------------------+


+---------------------------------+
|  Objects                        |
|   -------------                 |
| Object Data: Balance            |
|    ------------                 |
| Object Method: "debit"          |
|    ------------                 |
| Object Method: "credit"         |
|     ----------                  |
| Object Method: "getBalance"     |
+---------------------------------+

A Class describes an object COBOL class object and its instance objects. It contains nested programs for class methods and instance methods.

The source code for a class begins with the CLASS-ID header, and ends with the END CLASS header. The CLASS-ID names the class, and its superclass if it has one. A root class has no superclass. The CLASS-ID header also determines whether this class inherits data, and whether its own data is private or protected.

General Format

[IDENTIFICATION DIVISION .]

                            IS ABSTRACT 
    CLASS-ID . class-name-1 IS EXTERNAL 

                   PRIVATE   
          DATA IS  PROTECTED  
                   RESTRICTED 

          [INHERITS FROM class-name-2 [WITH DATA ]] .

    class-control
    shared-data 
    class-object
    object-program 

    END CLASS class-name-1

This example shows the main features of a class. 

 class-id. Example inherits    *> Class identification.
           from Base.          *> Also sets up any 
                               *> data inheritance (none 
                               *> in this example). 
 environment division.         *> Environment division 
                               *> header is optional.
                               *> All sections legal in 
                               *> MF or ANSI 85 COBOL 
                               *> environment division 
                               *> are valid, though not 
                               *> shown here. 
 ...
 object section.               *> Section containing OO 
                               *> specific environment 
                               *> information. 
 class-control.                *> Class control paragraph
                               *> names the files 
                               *> containing the   
                               *> executables for each
                               *> class.
 Example is class "exmp"       *> The executable for the
                               *> Example class is in  
                               *> file exmp.  
 Base is class "base" 
 CharacterArray is class "chararry"
 .                             *> Period terminates paragraph.
 data division.                *> Data division header is 
                               *> optional. 
                               *> All sections legal in 
                               *> MF or ANSI 85 COBOL 
                               *> data division are valid, 
                               *> though not shown here. 
 ...
 working-storage section.      
 ...
 procedure division.           *> procedure division is 
                               *> optional. You can  
                               *> use it for class 
                               *> initialization.  
 exit program.                 *> Terminates procedure division
                               *> division. 

     class-object              *> Defines the start of the class
                               *> object. 
     object-storage section.   *> Defines class object data
     ...

     ...
 
         method-id. "new".     *> Start of class method "new". 
         ...
         end method "new".     *> End of class method "new".
    end class-object.          *> End of the class object

    object.                    *> Start of the code 
                               *> defining behavior 
                               *> of instances  
                               *> of the class. 
    object-storage section.    *> Defines instance data. 
     ...
         method-id. "sayHello".*> Start of instance 
                               *> method "sayHello"
         ...
         end method "sayHello".*> End of instance method. 
    end object.                *> End of code for 
                               *> instance objects.  

 end class

I got to tell you, I look at this stuff, and just start to glaze over. The language has changed so radically that I can’t just ‘figure it out’. What’s funny is that the beta doesn’t include any documentation other than on-line help,
which is useless for learning a new language. Looking at this stuff just makes me hope that the other parts of COBOL 97 are a bit easier to learn and use, I will probably make use of this eventually, but I have trouble believing that HP is going to implement COBOL 97 in it’s entirety.

Now you are all in for a treat, for the next several months I will be doing a multi-part column comparing COBOL and C. It is probably 90% or more accurate, but I am sure there are one or two mistakes in it. You should find it interesting, and if you are having to learn, or want to learn C, it could even be helpful.