skip to main content

Object-oriented Programming : Methods : Method invocation

Method invocation
Any program or method can invoke a method to act on an object. The name of the method specified on the invocation statement will be the method executed. The invocation statement also allows arguments to be passed to the method and also allows the method to return a result.
    INVOKE an-account "deposit" USING in-amount
    INVOKE an-account "balance" RETURNING current-balance
    MOVE an-account:>balance TO current-balance
    WORKING-STORAGE.
    01 a-checking-account-object USAGE IS OBJECT REFERENCE CheckingAccount
    77 the-balance PIC S9(8)V99 VALUE ZERO.
    PROCEDURE DIVISION.
       INVOKE a-checking-account-object "balance" RETURNING the-balance. *> assume the object
    OBJECT.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    01  checking-account.
        03 customer-name    PIC X(35).
        03 current-balance  PIC S9(9)V99.
        03 date-opened      PIC 9(8).
    PROCEDURE DIVISION.
    METHOD-ID. balance.
    DATA DIVISION.
    LINKAGE SECTION.
    01  ls-balance          PIC S9(8)V99.
    PROCEDURE DIVISION RETURNING ls-balance.
       MOVE current-balance TO ls-balance.
       EXIT PROGRAM.
    END METHOD.

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left