Procedure Division Header COBOL

When it is present, the Procedure Division is identified by and must begin with the following header:

Procedure Division Header

The USING phrase of the Procedure Division header identifies the names used by the program for any parameters passed to it by a calling program or from the RM/COBOL Runtime Command.It is required only in one of the following circumstances:

  • If the object program is to be invoked by a CALL statement and that statement includes a USING phrase.
  • If the object program is to function as the first program in its run unit and it requires access to the text of the runtime command that invokes the object program.

In the first case, the parameters passed to the called program are identified in the USING phrase of the calling program’s CALL statement.The correspondence between the two lists of names is established on a positional basis.That is, the first data-name-1 in the USING list of the CALL statement in the calling program corresponds to the first data-name-1 in the USING list of the Procedure Division header in the called program, the second data-name-1 in the USING list of the CALL statement in the calling program corresponds to the second data-name-1 in the USING list of the Procedure Division header in the called program, and so forth.The two lists need not have the same number of operands, but operands for which there is no corresponding operand in the other list may not be referred to, nor may any of their subordinate data items, condition-names or index-names be referred to in the called program.

In the second case, there is only a single parameter, and it must be defined in the Linkage Section with entries similar to the following:

01 MAIN-PARAMETER.
02 PARAMETER-LENGTH PIC S9(4) BINARY (2).
02 PARAMETER-TEXT.
03 PARAMETER-CHAR PIC X OCCURS 0 TO 100 TIMES
DEPENDING ON PARAMETER-LENGTH.

The Procedure Division header should have the following form:

PROCEDURE DIVISION USING MAIN-PARAMETER.

Subscripted references to PARAMETER-CHAR can then be used to access the characters within the invocation line.There is further information in the describing the technique for passing a character-string to the first program in a run unit.

In either case, each data-name-1 and data-name-2 must be defined as a level 01 entry or a level 77 entry in the Linkage Section of the Data Division.A particular user-defined word may not appear more than once as data-name-1 or data-name-2.The data description entry for data-name-1 or data-name-2 must not contain a REDEFINES clause.However, data-name-1 or data-name-2 may be the object of a REDEFINES clause elsewhere in the Linkage Section.

If the reference to the corresponding data item in the CALL statement declares the parameter to be passed by content, the value of the item is moved when the CALL statement is executed and placed into a system-defined storage item possessing the attributes declared in the Linkage Section for data-name-1.

The data description of each parameter in the BY CONTENT phrase of the CALL statement must be congruent to the data description of the corresponding parameter in the USING phrase of the Procedure Division header.Two data descriptions are congruent if they specify the same size and, for numeric items, the same usage, scale and sign convention.For binary data items, congruency also depends on both items being allocated with the same number of bytes, which depends on specification of the same binary allocation override in the USAGE clause or matching configuration of the compiler with the BINARY-ALLOCATION and BINARY-ALLOCATION-SIGNED keywords of the COMPILER-OPTIONS configuration record when compiling each of the possibly separately compiled programs.

If the reference to the corresponding data item in the CALL statement declares the parameter to be passed by reference, the object program operates as if the data item in the called program occupies the same storage area as the corresponding data item in the calling program.If data-name-1 or any of its subordinate elements is referred to in the Procedure Division, it must not be defined as being longer than its corresponding data item in the calling program.

RETURNING is a synonym for GIVING.

The GIVING phrase identifies the name used by the program for a result value.It is required only when the calling program specifies a GIVING phrase in the CALL statement and the design of that calling program depends on a result being placed in its GIVING argument.That is, it is not an error if the calling program specifies a GIVING operand and the called program does not; in this case, the called program ignores and cannot affect the GIVING operand in the calling program.However, it is a data reference error to refer to data-name-2, or any of its subordinate data-names or condition-names, redefined data-names, or renamed data-names if the calling program does not have a GIVING phrase, except in certain contexts.When the calling program does not have a GIVING phrase, the contexts where an error will not occur are:

  • The ADDRESS OF special register, which will be equal to NULL in this case.
  • The USING or GIVING phrase of a CALL statement.In this case, the called program will receive an actual argument with a NULL base address. The called program would cause a data reference error if that program referred to the corresponding formal argument other than in the contexts described here.

Each reference to data-name-1 or data-name-2 in the called program is resolved in accordance with the description of data-name-1 or data-name-2 as given in the Linkage Section of the called program, except when they name a level 01 or level 77 entry and they are specified in the USING or GIVING phrase of a CALL statement, or when they are reference modified.In these two exception cases, the reference to data-name-1 or data-name-2 is resolved according to the description in the calling program.

A data item defined in the Linkage Section of the called program may be referred to within the Procedure Division of that program only if it satisfies one of the following conditions:

  • It is an operand in the USING phrase of the Procedure Division header and there is a corresponding operand in the USING phrase of the CALL statement of the calling program.
  • It is an operand in the GIVING phrase of the Procedure Division header and there is a corresponding operand in the GIVING phrase of the CALL statement of the calling program.
  • It is the target of a Format 5 SET statement using the SET ADDRESS OF data-name-1 format, where data-name-1 is the name of the data item and the sending pointer value is not a null pointer value.
  • It is subordinate to a data item that satisfies one of the preceding conditions.
  • It is defined with a REDEFINES or RENAMES clause, the object of which satisfies one of the preceding conditions.
  • It is an item subordinate to an item that satisfies the preceding condition.
  • It is a condition-name or index-name associated with a data item that satisfies any of the preceding conditions.
  • It is the operand of an ADDRESS special register.In this case,if none of the preceding conditions are satisfied, the ADDRESS special register will have a null pointer value.Thus, an IF statement may be used to verify that one of the preceding conditions has been satisfied by verifying that the ADDRESS of the data item is not equal to NULL.
  • It is the operand of a USING or GIVING phrase in a CALL statement.In this case, if none of the preceding conditions are satisfied, the program called by the CALL statement receives an omitted argument for its corresponding formal argument.

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics