Defining a class instance method

Define COBOL instance methods in the PROCEDURE DIVISION of the OBJECT paragraph of a class definition. An instance method defines an operation that is supported for each object instance of a class.

About this task

A COBOL instance method definition consists of four divisions (like a COBOL program), followed by an END METHOD marker.

Table 1. Structure of instance method definitions
Division Purpose Syntax
IDENTIFICATION (required) Name a method.
METHOD-ID paragraph for defining a class instance method (required)

AUTHOR paragraph (optional)
INSTALLATION paragraph (optional)
DATE-WRITTEN paragraph (optional)
DATE-COMPILED paragraph (optional)

ENVIRONMENT (optional) Relate the file-names used in a method to the corresponding file-names known to the operating system. INPUT-OUTPUT SECTION for defining a class instance method (optional)
DATA (optional) Define external files. Allocate a copy of the data. DATA DIVISION for defining a class instance method (optional)
PROCEDURE (optional) Code the executable statements to complete the service provided by the method. PROCEDURE DIVISION for defining a class instance method (optional)

Definition: The signature of a method consists of the name of the method and the number and type of its formal parameters. (You define the formal parameters of a COBOL method in the USING phrase of the method's PROCEDURE DIVISION header.)

Within a class definition, you do not need to make each method-name unique, but you do need to give each method a unique signature. (You overload methods by giving them the same name but a different signature.)

COBOL instance methods are equivalent to Java™ public nonstatic methods.

Example: defining a method