Skip to content

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:

  1. USING and CHAINING clauses are used to describe data elements that are being passed to a program that is serving as a subroutine.
  2. Data elements described by the USING clause correspond to data elements named in a CALL statement invoking the subroutine.
  3. Data elements described by the CHAINING clause correspond to data elements named in a CHAIN statement invoking the subroutine.
  4. All data items expressed in USING/CHAINING clauses must be defined in the LINKAGE SECTION of the program.
  5. Note that the CHAIN statement and CHAINING clause are recognized, and syntax is validated. However, the CHAIN statement/CHAINING clause are otherwise treated as commentary.
  6. 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:

  1. 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 the CALL’ing program .
  2. The BY VALUE clause indicates that the VALUE, 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 the CALL’ing program.
  3. 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 the CALL’ing program.
  4. BY REFERENCE is assumed as the default if no BY 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:

  1. The SIZE clause is only allowed when passing BY VALUE.
  2. SIZE IS AUTO causes the argument size to be matched to the size of the corresponding data item in the CALL’ing
  3. SIZE IS DEFAULT causes the argument size to be set to 4.
  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.

Back to top