COBOL method definition structure
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:
- Identification division
- Environment division (input-output section only)
- Data division
- Procedure division
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: COBOL 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.----------------------------------><
|
- METHOD-ID
- Identifies a method definition. See METHOD-ID paragraph for details.
- method-procedure-division-header
- Indicates the start of the procedure division and identifies method
parameters and the returning item, if any. See The procedure division header for details.
- END METHOD
- Specifies the end of a method definition.
Methods defined in an object definition are instance
methods. An instance method in a given class can access:
- Data defined in the data division of the object paragraph of that class (instance
data)
- Data defined in the data division of that instance method (method data)
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:
- Data defined in the data division of the factory paragraph of that class (factory
data)
- Data defined in the data division of that factory method (method data)
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.)
|