A COBOL method definition describes a method. You can specify method definitions only within the factory paragraph and the object paragraph of a class definition.
With the exception of COPY and REPLACE statements and the END METHOD marker, the statements, entries, paragraphs, and sections of a COBOL method definition are grouped into the following four divisions:
The end of a COBOL method definition is indicated by the END METHOD marker.
The following is the format for a COBOL method definition.
Format: method definition >>-+-IDENTIFICATION-+--DIVISION.--------------------------------> '-ID-------------' >--METHOD-ID--+---+--method-name-1--+---+-----------------------> '-.-' '-.-' >--+---------------------------------------+--------------------> '-other-identification-division-content-' >--+------------------------------------------------------------+--> '-ENVIRONMENT DIVISION.--method-environment-division-content-' >--+----------------------------------------------+-------------> '-DATA DIVISION.--method-data-division-content-' >--+--------------------------------------------------------------------------+--> '-method-procedure-division-header.--+-----------------------------------+-' '-method-procedure-division-content-' >--END METHOD--method-name-1.----------------------------------><
Methods defined in an object definition are instance methods. An instance method in a given class can access:
An instance method cannot directly access instance data defined in a parent class, factory data defined in its own class, or method data defined in another method of its class. It must invoke a method to access such data.
Methods defined in a factory definition are factory methods. A factory method in a given class can access:
A factory method cannot directly access factory data defined in a parent class, instance data defined in its own class, or method data defined in another method of its class. It must invoke a method to access such data.
Methods can be invoked from COBOL programs and methods, and they can be invoked from Java programs. A method can execute an INVOKE statement that directly or indirectly invokes itself. Therefore, COBOL methods are implicitly recursive (unlike COBOL programs, which support recursion only if the RECURSIVE attribute is specified in the program-ID paragraph.)