RETURNING phrase

The RETURNING phrase specifies a data item that is to receive the program, method, or function result. For function prototypes, the RETURNING phrase specifies the kind of function result.

data-name-2
data-name-2 is the RETURNING data item. data-name-2 must be a level-01 or level-77 item in the LINKAGE SECTION.
Note: An unbounded group cannot be specified as data-name-2.

In a method procedure division header, the data type of data-name-2 must be one of the types supported for Java™ interoperation, as listed in Interoperable data types for OO COBOL and Java.

The RETURNING data item is an output-only parameter. On entry to the method, the initial state of the RETURNING data item has an undefined and unpredictable value. You must initialize the PROCEDURE DIVISION RETURNING data item before you reference its value. The value that is returned to the invoking routine is the value that the data item has at the point of exit from the method. See RETURNING phrase for further details on conformance requirements for the INVOKE RETURNING identifier and the method RETURNING data item.

The PROCEDURE DIVISION RETURNING phrase must be specified for user-defined functions and function prototype definitions.

Do not use the PROCEDURE DIVISION RETURNING phrase in:

  • Programs that contain the ENTRY statement.
  • Nested programs.
  • Main programs: Results of specifying PROCEDURE DIVISION RETURNING on a main program are undefined. You should specify the PROCEDURE DIVISION RETURNING phrase only on called subprograms. For main programs, use the RETURN-CODE special register to return a value to the operating environment.