PreviousException Handling Tutorial (Windows & OS/2) GUI Programming Tutorial (Windows & OS/2)Next"

Chapter 10: Requirements-based Vocabulary Tutorial (Windows & OS/2)

Requirements-based vocabulary is a feature unique to Micro Focus Object COBOL. Requirements-based vocabulary enables you to create new verbs and functions related to types of application you are working on. This tutorial demonstrates this new feature, using the bank account classes introduced in the Inheritance tutorial.

This tutorial consists of the following sessions:

  1. Introducing the Vocabulary Example

  2. Using Requirements-based Vocabulary

Approximate time to complete: 10 minutes.

10.1 Introducing the Vocabulary Example

In this section you will load the Bank example and look at its components. Follow the steps below:

>>To look at the Bank vocabulary example

  1. Start the icon labeled Tutorial 8 in the COBOL Workbench Tutorials group.

    This starts the on-line Requirements-based Vocabulary Tutorial tutorial.

  2. Select the hotspot labeled Browse vocabulary (you will need to double-click or press Enter on OS/2), below the heading Using This Tutorial.

    This starts the Browser with the source files for the Account classes and a program called Bank2 loaded in. The Browser shows the hierarchy of the account classes.

    Account and its subclasses are the same class programs as used in the Inheritance tutorial. Bank2 is similar to Bank1, also used in the Inheritance tutorial, but uses verbs and functions defined with Requirements-based Vocabulary instead of the invoke verb.

  3. Select Bank2 in the class/program selector.

    Account.if and saccount.if are copyfiles used by Bank1. They are the class interface files which define new vocabulary for use with the Account and SavingsAccount classes. Because the methods of Account are inherited by all types of account, with no interface changes, the vocabulary defined in account.if applies to all the account classes. The saccount.if file defines extra vocabulary appropriate to SavingsAccount (and HighRateAccount which is a subclass of SavingsAccount).

  4. Select account.if in the file selector. If the file selector displays the file-name as account.if... double-click on it to load and parse the file.

    Look at the class-id header; it defines account.if as an external class. The Compiler does not generate any code for external classes.

  5. Select "openAccount" from the method/program selector.

    This has the same method-id, linkage section and procedure division header as the "openAccount" method in account.cbl. However, there are no executable statements in the procedure division. Instead, there is a syntax definition of a new verb, Create. The definition starts with the phrase invoked as. The syntax for defining new verbs and functions is covered in the chapter Requirements-based Vocabulary.

This is the end of the first session. In the next session you will look at some code which uses the new syntax.

10.2 Using Requirements-based Vocabulary

This session animates some source code which uses requirements-based vocabulary.

>>To animate the vocabulary example source code

  1. Select Check All from the Browser COBOL menu to check all the files in the application.

  2. Select Bank2 on the class/program selector.

  3. Select Animate from the COBOL menu.

  4. Step the lines below tag B002.

    The message to open a new CheckAccount is sent by the new verb create, which is defined in account.if. Execution switches to the "openAccount" method of Account (CheckAccount inherits the "openAccount" method from Account).

  5. Step through the account creation code until execution returns to the line below tag B003 of

  6. You can look at the definition of the create verb. This is in the account.if file. Press ctrl+home to go to the top of Bank2. Find the line copy "ACCOUNT.IF". Animator V2 defaults to showing the code inside the copyfile, so press page-down until you see the line below tag I001 (method-id. "openAccount").

    Below the procedure division header, is the invoked as phrase. The words in brackets [ ] are noise-words, included for readability. You don't have to include them when you use the create verb.

    Words inside angle brackets <> are the parameters to the routine, with the exception of <self>. <self> is the object reference to the object which receives the message. Every parameter in the definition of the verb is in the procedure division header using and returning clauses

    The procedure division header and linkage section match exactly those in the openAccount method of the Account class itself.

  7. Select Where from the View menu to return to the current execution point of the program.

  8. Step through the code of Bank2 until you reach tag B008.

    As you step through the code, you can see how the same verbs can be used for SavingsAccounts and CheckAccounts.

  9. Step the line below B008 (if balance(asAccount)...).

    This conditional statement uses the balance function. This is an example of a function definition. You can use it in the same sorts of ways as you can use an intrinsic COBOL function; for example in a conditional statement or as part of a compute statement.

  10. Step through the code until your Animator V2 displays the "Stop run encountered..." message.

    Select Exit from the Animator V2 File menu to quit Animator V2.

  11. Select Exit from the on-line help File menu to quit the on-line tutorial.

This ends this tutorial on Requirements-based Vocabulary. You can study account.if and saccount.if to see how you can define vocabulary for any objects you create.

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

PreviousException Handling Tutorial (Windows & OS/2) GUI Programming Tutorial (Windows & OS/2)Next"