PROCEDURE DIVISION for defining a class instance method
Code the executable statements to implement the service
that an instance method provides in the PROCEDURE DIVISION
of
the instance method.
About this task
You can code most COBOL statements in the PROCEDURE
DIVISION
of a method that you can code in the PROCEDURE
DIVISION
of a program. You cannot, however, code the following
statements in a method:
ENTRY
EXIT PROGRAM
- The following obsolete elements of the 85 COBOL Standard:
ALTER
GOTO
without a specified procedure-nameSEGMENT-LIMIT
USE FOR DEBUGGING
Additionally, because you must compile all
COBOL class definitions with the THREAD
compiler
option, you cannot use SORT
or MERGE
statements
in a COBOL method.
You can code the EXIT METHOD
or GOBACK
statement
in an instance method to return control to the invoking client. Both
statements have the same effect. If you specify the RETURNING
phrase
upon invocation of the method, the EXIT METHOD
or GOBACK
statement
returns the value of the data item to the invoking client.
An
implicit EXIT METHOD
is generated as the last statement
in the PROCEDURE DIVISION
of each method.
You
can specify STOP RUN
in a method; doing so terminates
the entire run unit including all threads executing within it.
You
must terminate a method definition with an END METHOD
marker.
For example, the following statement marks the end of the credit
method:
End method "credit".
USING phrase for obtaining
passed arguments: Specify the formal parameters to a method, if
any, in the USING
phrase of the method's PROCEDURE
DIVISION
header. You must specify that the arguments are
passed BY VALUE
. Define each parameter as a level-01
or level-77 item in the method's LINKAGE SECTION
.
The data type of each parameter must be one of the types that are
interoperable with Java™.
RETURNING phrase for returning
a value: Specify the data item to be returned as the method result,
if any, in the RETURNING
phrase of the method's PROCEDURE
DIVISION
header. Define the data item as a level-01 or level-77
item in the method's LINKAGE SECTION
. The data type
of the return value must be one of the types that are interoperable
with Java.
Coding interoperable data types in OO COBOL and Java
Overriding an instance method
Overloading an instance method
Comparing and setting object references
Invoking methods (INVOKE)
Compiling, linking, and running OO applications
THREAD
The procedure division header (Enterprise COBOL for z/OS Language Reference)