Subprogram Parameters

Usually you need to pass several different fields to a COBOL subprogram.

A common approach is to lump all these fields together into a single group item. The alternative is to pass each field as a separate parameter. Sometimes one approach is appropriate, and sometimes the other is appropriate.

Lumped parameters may be appropriate when:

In the absence of these special factors, the use of separate parameters tends to make your code smaller and more understandable. The purpose of your CALL statement is more readily apparent.

For example: suppose we have a subprogram which reformats a name. Its input is a fixed-field group item, with first name, middle name, and last name. Its output is text: last name, comma, first name, and middle initial, with mixed upper and lower case as appropriate.

Let's further suppose that we have two different names to reformat: an employee's name and his spouse's name.

With a single lumped parameter, we code something like the following:

[yuk] [Warning: bad code ahead]

     MOVE EMP-NAME          TO FORMNAME-NAME-IN.
     CALL 'FORMNAME'  USING FORMNAME-PARM.
     MOVE FORMNAME-NAME-OUT TO EMP-NAME-OUT.
*
     MOVE SPOUSE-NAME       TO FORMNAME-NAME-IN.
     CALL 'FORMNAME'  USING FORMNAME-PARM.
     MOVE FORMNAME-NAME-OUT TO SPOUSE-NAME-OUT.
Now suppose we pass two separate parameters (we retain the fixed-field name as a group item, since it forms a natural aggregation):
     CALL 'FORMNAME' USING EMP-NAME
                           EMP-NAME-OUT.
     CALL 'FORMNAME' USING SPOUSE-NAME
                           SPOUSE-NAME-OUT.
This version is not only shorter, but also easier to read, and less likely to be corrupted or obscured by later maintenance.
homeCOBOL Home [style forum]COBOL Style Forum