PreviousObject COBOL Tutorials (Windows & OS/2) Objects and Messages Tutorial (Windows & OS/2)Next"

Chapter 4: Class Browser Tutorial (Windows & OS/2)

The COBOL Class Browser is a tool for developing Object COBOL programs. It provides you with a high-level view of an Object COBOL application, enabling you to see the classes in the application, and the class and object methods implemented. The Class Browser also enables you to start the COBOL Checker and Animator V2 so that you can check and debug your programs.

This tutorial gives you a short tour around the main Browser functions. It is not a comprehensive guide to the Browser. For more information, see the chapter Using Browser in your Object COBOL User Guide, and also the Class Browser on-line reference.

This tutorial consists of the following sessions:

  1. Starting the Browser

  2. Browser Components

  3. Changing View

  4. Creating a New Program

  5. Editing

  6. Compiling

  7. Animating a Program

  8. Finding Methods

  9. Closing the Browser

Time to complete: 25 minutes.

4.1 Starting the Browser

You can start the Browser from the Class Browser icon or from the command line. The on-line Class Browser Reference tells you how to create new Windows or OS/2 icons to start the Browser for different projects.

In this tutorial you will start it from an icon in the COBOL Workbench Tutorials group.

>>To start the Class Browser

  1. Start the icon labeled Class Browser in the COBOL Workbench Tutorials group.

    This starts the on-line Class Browser tutorial.

  2. Select the hotspot marked Start Browser below the heading Using This Tutorial.

    The Browser window appears, then there is a short delay while the Browser loads the files listed in a project file (inherit.prj). This tutorial uses the same files as used in one of the later tutorials (on Inheritance).

You can now move on to the next session, which describes the Browser's components.

4.2 Browser Components

In this session, you will look at the main Browser components. The main window area is divided into four panes. The panes along the top, from left to right are:

Beneath these is the:

Follow the steps below:

>>To try the Browser selectors

  1. Select Account on the Class/Program selector (you may have to use the scrollbar at the right of this pane to find it).

    The file selector now displays the file-names for all the source files used by the Account class program. Some file-names are followed by an ellipsis (...), which means that the Browser has not yet loaded and parsed the file.

  2. Select "openAccount" from the method/section selector.

    The text editing pane displays the code for this method.

You can now move on to the next session, which describes the Browser's different view functions.

4.3 Changing View

In this session you will try some of the Browser functions which present the information in the selector panes in different ways.

>>To try different Browser views

  1. Reselect account.cbl in the file selector pane, then click on the View menu.

    This menu is divided into three groups of items; the top group of items changes the view in the class/program selector, and the two groups below change the display in the method/section selector. The checkmarks next to Nested Programs and File Structure tell you that the method/section selector is currently displaying a list of all the nested programs in account.cbl, in the order in which they appear in the file. Object COBOL uses nested programs for methods, so the nested programs view shows you all the methods for a program.

  2. Select Sorted Sections from the View menu.

    The methods are now listed in alphabetical order, rather than the order in which they appear in the file. However, the class methods are still listed before the instance methods. The instance methods appear below the "object." entry in the method/section selector.

  3. Select COBOL Sections from the View menu.

    The method/section selector now displays the divisions and sections in the program, as well as the methods.

  4. Select Program Files from the View menu.

    The Browser rearranges the contents of the class/program selector into alphabetical order.

  5. Now select Class Hierarchy from the View menu.

    There is a pause while the Browser sorts the contents of the class/program selector into an inheritance hierarchy (this is the default view). Each program appears below its superclass, with different levels of indent indicating how far a class is down the hierarchy. If you scroll to the top of the class/program selector, you can see that Base is at the top of the hierarchy. Account, an immediate subclass of Base, is indented one space in. SavingsAccount is a subclass of Account and is indented a further space.

You can now move on to the next session, which describes how you can create a new program.

4.4 Creating a New Program

In this session you will use the Browser to create a new program file for an Object COBOL class.

>>To create a new program

  1. Select New Program from the File menu.

    This displays the Create File dialog box. Type tutor1.cbl into the File field and push the default button (this is labelled OK, Create or Open depending on your operating system).

  2. This displays the Enter New Program Name dialog box. Tutor1 is displayed as the default. Push the OK button. TUTOR1 will be used as the program-id.

  3. Select the Program Files view, and scroll down the class/program selector to Tutor1.

  4. Select TUTOR1.CBL in the file selector.

    The method/section selector displays a set of divisions and sections for a COBOL program. When you tell the Browser to create a new program or class, the Browser creates a skeleton from a template file. The templates for programs and Object COBOL classes are different, and you can customize them (see your on-line COBOL Browser Reference for details).

You can now move on to the next session, which shows you how you can edit the program you have created.

4.5 Editing

In this session you will use the text editing pane to enter a short program.

>>To edit a program

  1. Select working-storage section from the method/section selector. Click the mouse cursor directly below the "w" of working-storage section in the text editing pane to put the text cursor there.

  2. Enter the line of code below. There is a deliberate mistake in it, which is used to illustrate the syntax errors view in a later part of this tutorial. Enter it exactly as shown.
        01 aVariable       PIC 94)        comp-5.

  3. Select main section from the method/section selector. Click the cursor directly below the "m" of main section in the text editing pane.

  4. Enter the two lines of code below:
        display "I am a test program."
        .

  5. Select Save from the File menu.

You can now move on to the next session, which shows you how to compile a program.

4.6 Compiling

In this session you will compile tutor1.cbl, and correct the error in it.

>>To compile a program

  1. Select Check from the COBOL menu.

    There is a pause while the Browser starts a background session and runs the Checker. Then the entries in the method/section selector are replaced by a single line:

    * 230-s PICTURE string has illegal precedence or illegal character

    (on some displays you will have to select the message and scroll it horizontally with the right cursor key to see the whole message).

    In the other two selectors, Tutor1 entries are marked with a hash (#). These indicate that the Checker has found syntax errors, and their general location.

  2. Select the View menu, and you can see from the check mark that Browser has automatically selected the Syntax Errors View.

    The method/section selector now displays only those sections which contain syntax errors, and displays the error message rather than the section name. In this case it displays the message:

    * 230-s PICTURE string has illegal precedence or illegal character

  3. Select the error message.

    The text editing pane displays the incorrect code, with the offending line highlighted to indicate the error.

  4. Type the missing parenthesis between the 9 and the 4 in the line which starts 01 aVariable....

  5. Check the program again. You are prompted to save tutor1.cbl. Push the Yes button.

    After a pause, the Browser switches back to the File Structure view, indicating that the program has no syntax errors.

    If the method/section selector selector appears to have no entries, it is because you left it scrolled too far to the right when you read the error message (in step 1 above). Click on the selector and press the <left-arrow> key until you can see the entries in the pane.

You can now move on to the next session, which shows you how to animate the program you have just compiled.

4.7 Animating a Program

In this session, you will animate Tutor1.

>>To animate Tutor1

  1. With TUTOR1 selected in the class/program selector, select Animate from the COBOL menu.

    You are prompted by a dialog box to save changes. This is because you have added an extra program to the project.

  2. Push the No button so that the project file is not updated.

    This starts Animator V2.

    While Animator V2 is active, Browser editing functions are disabled. This is because the Browser unlocks all the files loaded into it. There is a brief pause, while Animator V2 starts up. You can now animate the program.

  3. Select Run from the Animator Execute menu to run tutor1.int.

    For full information on Animator V2, use its on-line help. Select General Help or Help Index from the Animator Help menu. You can also read about Animator V2 in your Workbench User Guide.

  4. When you have finished with Animator, select Exit from the File menu to close Animator down and return to the Browser.

    Browser editing is reenabled.

You can now move on to the next session, which shows you how to use the Browser to find where different methods are implemented, and the interface for using them.

4.8 Finding Methods

The Browser has a function to help you find the implementation of methods. In this session you will use the Browser function to find implementations of some of the methods of the Account classes.

>>To find method implementors

  1. Select Find Method Signatures from the Help menu.

    The Browser opens a new window, Method Signatures. In the left-hand pane of the window is a list of all the methods defined in the programs loaded into the Browser.

  2. Select gettype from the left-hand pane (this shows all method names in lower-case).

    A template invoke statement for using the "getType" method appears in the right hand-pane. You can copy this to your source code and edit it.

  3. Press the Copy to Clipboard button.

  4. Select Tutor1 from the class/program selector, then select main section from the method/section selector.

  5. Move the text cursor to the line below the display statement.

  6. Select Paste from the Edit menu.

    The code is pasted into your program. You can now edit it to turn it into an executable statement.

    You can now move on to the next session, which shows you how to exit from the Browser.

If you lose the Method Signatures window behind other windows, you can reselect it from the Help menu or find it on the Windows or PM Task List (press Ctrl+Esc to display the Task List).

4.9 Closing the Browser

In this session you will close the Browser.

  1. Select Exit from the Browser File menu. You are prompted:

    Do you wish to save changes?

  2. Push the No button. If you push Yes, the Browser will add Tutor1 to the project index file for the inheritance example (although you could always remove it subsequently with the Remove Program function on the File menu).

  3. Select Exit from the on-line help File menu to shut down the on-line tutorial.

4.10 Summary

This concludes the Class Browser tutorial. An OO Object COBOL application consists of many short pieces of code representing methods and the Class Browser enables you to move rapidly between them much more quickly and easily than you could with a conventional editor.

In this tutorial you also learned how to use the Browser to navigate the classes and methods of a project, and how to use the Browser for the different parts of the edit/check/animate cycle.


Copyright © 1999 MERANT International Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.

PreviousObject COBOL Tutorials (Windows & OS/2) Objects and Messages Tutorial (Windows & OS/2)Next"