PreviousException Handling Tutorial Using Objects in ProgramsNext

Chapter 9: Requirements-based Vocabulary Tutorial

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.

9.1 Introducing the Vocabulary Example

In this section you will look at the components of the Bank vocabulary example. Follow the steps below:

To look at the Bank vocabulary example:

  1. Use Infomgr to locate the demonstration programs and transfer them to working directory.

  2. Load bank2.cbl into the Object COBOL editor.

  3. The first two statements in the program are COPY statements (page down to just below the introductory comments).

    Account.if and saccount.if are copyfiles used by bank2. 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. Put the cursor on the statement copy account.if and press the Alt-F2=library key to view account.if.

    The Class-Id header at the start of account.if defines it as an external class. The Compiler does not generate any code for external classes.

  5. Find the "openAccount" method.

    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.

  6. Look at the definition of the create verb.

    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 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.

9.2 Using Requirements-based Vocabulary

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

To animate the vocabulary example source code

  1. Use Infomgr to locate the demonstration programs and transfer them to working directory.

  2. Run the supplied shell script vocascrp.

    This compiles bank2.cbl and the account classes.

  3. Start animating bank2. Enter the following command line:

    anim bank2

    Animator starts with the statement below tag B002 highlighted ready for execution.

  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. 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.

  7. 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.

  8. Step through the code until you see the Stop Run message at the bottom of the Animator screen.

  9. Press the Esc key to exit Animator.

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 Using Objects in ProgramsNext