      $set mfoo ooctrl(+n)
      ************************************************************************
      * Copyright (C) 1991-1999 Micro Focus International Ltd.
      * All rights reserved.
      *  
      * This demonstration program is provided for use by users of 
      * Micro Focus products (the "Software") and may be used, 
      * modified and distributed as part of your application provided 
      * that you properly acknowledge the copyright of Micro Focus in this
      * material.
      *     
      * All conditions, warranties and undertakings, express or implied, 
      * statutory or otherwise, on the part of Micro Focus are excluded, 
      * including without limitation those of merchantability or fitness  
      * for purpose. This shall not, however, purport to exclude or 
      * restrict the liability of Micro Focus to any extent not 
      * permitted by law.
      *
      * IN NO EVENT WILL MICRO FOCUS BE LIABLE FOR ANY INDIRECT, 
      * INCIDENTAL, SPECIAL, CONSEQUENTIAL OR OTHER DAMAGES ARISING OUT 
      * OF THE USE OF THE DEMONSTRATION PROGRAM DISTRIBUTED WITH THE 
      * SOFTWARE, WHETHER OR NOT INFORMED OF THE POSSIBILITIES OF 
      * DAMAGES IN ADVANCE.  THESE LIMITATIONS APPLY TO ALL CAUSES OF 
      * ACTION, INCLUDING BREACH OF CONTRACT, BREACH OF WARRANTY, STRICT
      * LIABILITY, AND ANY ACTIONS IN TORTS.
      ************************************************************************
      *
      * Account is the base class of the various types of accounts.
      * It is created by calling method "openAccount".
      *
      ************************************************************************

       class-id. Account data is protected
                   inherits from Base.

        object section.
        class-control.
           Account is class "account"
           Base is class "base"
           ExceptionManager is class "exptnmgr"
           .
       working-storage section.
       copy "accinfo.cpy".
       class-object.
       object-storage section.

           01 nextAccountNumber        pic 9(8) value 0.
      *------------------------------------------------------------
      * Open a new account for lsName with initialValue
      *------------------------------------------------------------

       method-id. "openAccount".
       linkage section.
       01 lsName           pic x(accNameLength).
       01 lsAccount        usage object reference.
       01 lsInitialValue   pic s9(10)v99.
       procedure division using lsName lsinitialValue
                      returning lsAccount.
      *----A001. Create a new instance of account.
           invoke super "new" returning lsAccount
      *----A002. Initialize the account instance data.
           invoke self "setNextAccountNumber"
           invoke lsAccount "initAccount" using lsName lsInitialValue
                                                nextAccountNumber
           exit method.
       end method "openAccount".
      *------------------------------------------------------------
      * Set a new account number for the next account. Ifthis is
      * first time the program has been run, initialize the account
      * number.
      *------------------------------------------------------------
       Method-id. "setNextAccountNumber".
       procedure division.
      *----Test whether the account number has been initialized.
           if nextAccountNumber = 0
               invoke self "getFirstAccountNumber"
                                           returning nextAccountNumber
           else
               add 1 to nextAccountNumber
           end-if
           exit method.
       end method "setNextAccountNumber".

       method-id. "initializeClass".
       local-storage section.
       01 lsErrorNumber            pic x(4) comp-5.

       procedure division.
      *----A000. Register a message file for the account classes.
           invoke ExceptionManager "registerMessageFile"
                                    using "bank" "account"
                                returning lsErrorNumber
           exit method.
       end method "initializeClass".

       end class-object.
       Object.

       object-storage section.
      *----Instance data common to all accounts.
           01 balance              pic S9(10)v99.
           01 aName                pic x(accNameLength).
           01 accountNumber        pic 9(accNoLength).
      *----The charge period variable ensures that interest and bank
      *    charges are only debited once for each period. In a real
      *    application this would be linked to the date in some way.
           01 chargePeriod         pic x comp-5.
               88 newPeriod        value 1.
               88 chargesApplied   value 0.

      *------------------------------------------------------------
      * Withdraw lsAmount from this account
      *------------------------------------------------------------
       method-id. "withdraw".
       working-storage section.
       01 lsErrorNumber          pic x(4) comp-5.
       01 lsErrorObject          object reference.
       linkage section.
       01 lsAmount pic 9(10)v99.

       procedure division using lsAmount.
      *----A010. Ensure that there are sufficient funds to cover the
      *    withdrawal.
           if lsAmount <= balance
      *----A011. Make the withdrawal.
               subtract lsAmount from balance
           else
      *----A012. Raise an exception if there are insufficient funds
      *          If there is no exception handler in place to trap
      *          this error, the default exception handler stops the
      *          application.
               invoke ExceptionManager "queryMessageFile"
                                       using "bank" "account"
                                   returning lsErrorNumber
               add debitOverdrawsAccount to lsErrorNumber
               invoke self "raiseException" using lsErrorNumber
                                        returning lsErrorObject
          end-if
          exit method.
       end method "withdraw".

      *------------------------------------------------------------
      * Deposit lsAmount to this account
      *------------------------------------------------------------
       method-id. "deposit".
       linkage section.
       01 lsAmount pic 9(10)v99.

       procedure division using lsAmount.
      *----A020. Deposit money to the account.
           add lsAmount to balance
           exit method.
       end method "deposit".
      *------------------------------------------------------------
      * Returns name of account holder
      *------------------------------------------------------------
       method-id. "getName".

       linkage section.
           01  lsName              pic x(accNameLength).

       procedure division returning lsName.
      *----A030. Return the customer name.
           move aName to lsName
       exit method.
       end method "getName".

      *------------------------------------------------------------
      * Returns account number
      *------------------------------------------------------------
       method-id. "getAccountNumber".

       linkage section.
       01 lsAccountNumber    pic 9(accNoLength).

       procedure division returning lsAccountNumber.
      *----A040. Return the account number.
           move AccountNumber to lsAccountNumber
       exit method.
       end method "getAccountNumber".
      *------------------------------------------------------------
      * PRIVATE. Initialize this account with the name lsName and the
      * amount lsInitialValue.
      *------------------------------------------------------------
       method-id. "initAccount".
       linkage section.
       01 lsInitialValue       pic s9(10)v99.
       01 lsName               pic x(80).
       01 lsAccountNumber      pic 9(8).

       procedure division using lsName lsInitialValue lsAccountNumber.
      *----A050. Initialize the account instance data.
           move lsName to aName
           move lsInitialValue to balance
           move lsAccountNumber to accountNumber
      *----A051. Ensures that charges/interest are only debited/credited
      *          once for each charging period.
           set newPeriod to true
           exit method
       end method "initAccount".

      *------------------------------------------------------------
      * Starts a new charge/interest period.
      * The charge period variable ensures that interest and bank
      * charges are only debited once for each period. In a real
      * application this would be linked to the date in some way.
      *------------------------------------------------------------
       method-id. "newPeriod".

       procedure division.
      *----A060. Set the flag.
           set newPeriod to True
       exit method.
       end method "newPeriod".
      *------------------------------------------------------------
      * Return the balance for this account
      *------------------------------------------------------------
       method-id. "getBalance".
       linkage section.
       01 lsAmount pic S9(10)v99.

       procedure division returning lsAmount.
      *----A070. Return the balance.
           move balance to lsAmount
           exit method.
       end method "getbalance".
      *-----------------------------------------------------------------
      * Return the contents of this account as a string.
      * Provided to enable display of accounts on listboxes.
      *-----------------------------------------------------------------
       method-id. "getValue".
       local-storage section.
           01  accountType        pic x(accTypeLength).
           01  i                  pic x comp-5.
       linkage section.
           01  displayString       pic x(accDisplayLength).

       procedure division returning displayString.
      *----A0070. Return a string showing the account type, number
      *           and name.
           invoke self "getType" returning accountType
           move spaces to displayString
           move accountNumber to displayString(1:accnoLength)
           add 2 to accNoLength giving i
           move accountType to displayString (i:accTypeLength)
           add accTypeLength to i
           move aName to displayString (i:accNameLength)
           exit method.
       end method "getValue".
      *-----------------------------------------------------------------
      * Return the size of the string returned by getValue.
      * Provided to enable display of accounts on listboxes.
      *-----------------------------------------------------------------
       method-id. "size".

       linkage section.
            01  aSize           pic x(4) comp-5.

       procedure division returning aSize.
      *----C080. Return the size of the display string.
           move accDisplayLength to aSize
           exit method.
       end method "size".
       end object.
       end class Account.
