The USING Phrase
The USING phrase makes data items defined in a calling program available to a called subprogram.
The following rules for the USING phrase assume that the calling and called
programs are written in COBOL.
- The USING phrase is specified in the Procedure Division header if, and only if, this program is a subprogram invoked by a CALL statement that itself contains a USING phrase. For each CALL USING statement in a calling program, there must be a corresponding USING phrase specified in a called subprogram
- The USING phrase is valid in the Procedure Division header of a called subprogram.
- Each USING identifier must be defined as a level-01 or level-77 item in the Linkage Section of the called subprogram
- A USING identifier must not contain a REDEFINES clause
- A particular user-defined word cannot appear more than once as data-name-1
- In a calling program, the USING phrase is valid for the CALL statement; each USING identifier must be defined as a level-01, level-77, or an elementary item in the Data Division
The maximum number of data-names that can be specified is 255 when a program
is called with a LINKAGE TYPE of program. For programs called with LINKAGE
TYPE of procedure, the maximum number of data-names is 16,382.
- The order of appearance of USING identifiers in both calling and called subprograms determines the correspondence of single sets of data available to both programs. The correspondence is positional and not by name. Corresponding identifiers must contain the same number of characters, although their data descriptions need not be the same. For index-names, no correspondence is established; index-names in calling and called programs always refer to separate indexes.
- The identifiers specified in a CALL USING statement name data items available to the calling program that can be referred to in the called program; a given identifier can appear more than once. These items are defined in any Data Division section.
- A USING identifier containing the GLOBAL clause can be specified in only one Procedure Division header in a compilation unit.
An identifier should not appear more than once in a Procedure Division USING phrase.
Results are unpredictable when multiple arguments are received into the same identifier.
- Data items defined in the Linkage Section of the called program may be referenced within the Procedure Division of that program
if, and only if, they satisfy one of the following conditions:
- They are operands of the USING phrase of the Procedure Division header
- They are defined with a REDEFINES or RENAMES clause, the object of which satisfies the above condition
- IBM ExtensionIBM Extension They are used as arguments of the ADDRESS OF special register End of IBM ExtensionEnd of IBM Extension
- They are items subordinate to any item which satisfies the condition in the rules above
- They are condition-names or index-names associated with data items that satisfy any of the above conditions.