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 CALL
ing 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 CALL
ing program.
General Format:
[ { USING } ]
{ CHAINING }
General Rules:
USING
andCHAINING
clauses are used to describe data elements that are being passed to a program that is serving as a subroutine.- Data elements described by the
USING
clause correspond to data elements named in aCALL
statement invoking the subroutine. - Data elements described by the
CHAINING
clause correspond to data elements named in aCHAIN
statement invoking the subroutine. - All data items expressed in
USING
/CHAINING
clauses must be defined in theLINKAGE SECTION
of the program. - Note that the
CHAIN
statement andCHAINING
clause are recognized, and syntax is validated. However, theCHAIN
statement/CHAINING
clause 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 USING
clause.
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 REFERENCE
clause 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 VALUE
clause 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 CONTENT
clause 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 REFERENCE
is assumed as the default if noBY
clause 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
SIZE
clause is only allowed when passingBY VALUE
. SIZE IS AUTO
causes the argument size to be matched to the size of the corresponding data item in theCALL
’ingSIZE IS DEFAULT
causes 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.