Procedure Division
The Procedure Division clause contains the statements that the program executes, and describes data items that may be passed to the program from a CALLing program, or from the command-line.
Procedure Division Clause
General Format:
Procedure Division
[ { USING } ]
{ CHAINING }
[ { BY REFERENCE } ]
{ BY VALUE }
{ BY CONTENT }
[ [ UNSIGNED ] SIZE [ IS ] { AUTO } ]
{ DEFAULT }
{ integer }
[ [ OPTIONAL ] { param } ... ]
[ RETURNING ] [ { param } ... ].
[ DECLARATIVES.
{ procedure-sect SECTION [segment-no] .
use-statement
[ procedure-para.
[ procedure-statement ] ... ] ... } ...
END DECLARATIVES. ]
{ procedure-sect SECTION [segment-no] .
[ procedure-para.
[ procedure-statement ] ... ] ... } ...
Syntax:
The clauses supported in the Procedure Division statement are described below.
USING/CHAINING Clause
USING is followed by a parameter or list of parameters, whose order matches the order of the parameters listed in a CALL statement in a CALLing program.
General Format:
[ { USING } ]
{ CHAINING }
General Rules:
USINGandCHAININGclauses are used to describe data elements that are being passed to a program that is serving as a subroutine.- Data elements described by the
USINGclause correspond to data elements named in aCALLstatement invoking the subroutine. - Data elements described by the
CHAININGclause correspond to data elements named in aCHAINstatement invoking the subroutine. - All data items expressed in
USING/CHAININGclauses must be defined in theLINKAGE SECTIONof the program. - Note that the
CHAINstatement andCHAININGclause are recognized, and syntax is validated. However, theCHAINstatement/CHAININGclause are otherwise treated as commentary. - The usage of a redefined field in the Linkage Section is allowed. The redefined field may subsequently be referenced in the
Procedure Division USINGclause.
BY Clause
The BY clause describes the manner in which data is passed to a subprogram.
General Format:
{ BY REFERENCE }
{ BY VALUE }
{ BY CONTENT }
General Rules:
- The
BY REFERENCEclause indicates that the address of the data item has been passed through the Linkage Section. Updates to the data item are made directly to the memory address of the data item, and changes to the value of the data item will be seen in theCALL’ing program . - The
BY VALUEclause indicates that theVALUE, rather than memory address of the item is passed through the Linkage Section. Updates to the data item will only be seen locally in the sub-program, and will not be returned through the data item to theCALL’ing program. - The
BY CONTENTclause indicates that a copy of the address of the data item has been passed through the Linkage Section. Updates to the data item will only be seen locally in the sub program, and will not be returned through the data item to theCALL’ing program. BY REFERENCEis assumed as the default if noBYclause is present.
SIZE Clause
The SIZE clause describes the size, in bytes, of a data item.
General Format:
[ [ UNSIGNED ] SIZE [ IS ] { AUTO } ]
{ DEFAULT }
{ integer }
General Rules:
- The
SIZEclause is only allowed when passingBY VALUE. SIZE IS AUTOcauses the argument size to be matched to the size of the corresponding data item in theCALL’ingSIZE IS DEFAULTcauses the argument size to be set to 4.SIZE IS [integer]can be used, where valid values for integer are 1, 2, 4, and 8.
OPTIONAL Clause
The OPTIONAL clause may be used to indicate a data item being passed BY REFERENCE is not required.
General Format:
[ OPTIONAL ]
General Rules:
There are no General Rules.
RETURNING Clause
The RETURNING clause describes data items to be returned to the CALL'ing program.
General Format:
[ RETURNING ] [ { param } ... ].
Syntax:
param must be declared in the Linkage Section.
General Rules:
The RETURNING clause causes the value of param to be returned to the data item named in the RETURNING clause of the CALL’ing program.