The PROCEDURE DIVISION Header

The Procedure Division is identified by and must begin with a header in one of the following formats:

General Formats
Format 1

MFFormat 2

MF

Directives
  1. In addition to Compiler directives which provide flagging and modify the reserved word list, the following directives may impact either the syntax or the semantics described in this section.
Syntax Rules
    All Formats
  1. MFMnemonic-name is necessary only if the runtime element is being invoked by another runtime element and that runtime element is using a calling convention other than that used as default by your COBOL system. Typically, the default COBOL calling convention is consistent with that used by a significant implementation of a non-COBOL language for the run-time environment.

    Mnemonic-name must be defined in the Special-Names paragraph. See the topic The Special-Names Paragraph in the chapter Environment Division for details of how to do this and your COBOL system documentation on interfacing for details of which calling conventions are supported in your run time environment.

  2. MFCHAINING and USING are equivalent.
  3. ISO2002MFIf data-name-1 or data-name-2 is defined with the USAGE OBJECT REFERENCE clause, the ACTIVE-CLASS phrase must not be specified.
  4. ISO2002MFData-name-3 must be defined as a level 01 or level 77 entry in the Linkage Section. The data description entry for data-name-3 must not contain a REDEFINES clause. A data item elsewhere in the Linkage Section may specify REDEFINES data-name-3.
  5. ISO2002MFData-name-3 must not be the same as data-name-1 or data-name-2.
  6. Format 1
  7. Data-name-1 must be defined as a level 01 or a level 77 entry in the Linkage Section

    MF, File Section or Working-Storage Section

    . A particular user-defined word must not appear more than once as data-name-1.

    OSVSVSC2MFIt may appear more than once.

    The data description entry for data-name-1 must not contain a REDEFINES clause.

    OSVSVSC2MFIt may contain a REDEFINES clause.

    Data-name-1 may, however, be the object of a REDEFINES clause elsewhere in the Linkage Section.

  8. ISO2002MFData-name-2 must be defined as a level 01 or a level 77 entry in the Linkage Section

    MF, File Section or Working-Storage Section , unless the source unit is a method definition or method prototype definition

    . Data-name-2 must be defined as a data item of class numeric, object or pointer.

    MFData-name-2 can be of any class, but the length must be no greater than 8 bytes.

  9. ISO2002MFThe RETURNING phrase must be specified in a function definition and in a function prototype definition.
  10. ISO2002MFThe RETURNING phrase may be specified in a method definition, a program definition or a program prototype.
  11. MFFormat 2
  12. MFFormat 2 can only be used in a program in which the EXTERNAL clause is specified in the Program-ID paragraph, that is a call prototype.
  13. MFData-name-1 and data-name-2 must be defined as 01 level records in the Linkage Section.
  14. MFTypedef-name-1, typedef-name-2, and typedef-name-3 must be previously defined in the same source file as a programmer-defined usage by means of a TYPEDEF clause.
General Rules
    All Formats
  1. Up to five data-names are permitted in the USING phrase.

    ISO2002MFXOPENUp to sixty-two data-names are permitted in the USING phrase.

  2. Both the BY REFERENCE and the BY VALUE phrases are transitive across the parameters that follow them until another BY REFERENCE or BY VALUE phrase is encountered. If neither the BY REFERENCE nor the BY VALUE phrase is specified prior to the first parameter, the BY REFERENCE phrase is assumed.
  3. Format 1
  4. MFMnemonic-name identifies the calling convention that this program assumes has been adopted by the calling program that invokes it. This calling convention is also used for subsequent entry points unless those entry points specify a calling convention explicitly. If the calling convention actually used is different to that implied by mnemonic-name, then the COBOL system may become corrupt.
  5. MFIf data-name-1 is defined as a level 01 or a level 77 entry in the File Section or Working-Storage Section then the activated runtime element operates as if a data item had been declared in the Linkage Section with the same data declaration as data-name-1 and the contents of that data item were moved to data-name-1 prior to executing the first statement in the activated runtime element. In an initial program, these values are overwritten by the initialization of the program's working storage data and are therefore not available to the called program.
  6. If the activating runtime element is COBOL the following rules apply. If the activating runtime element is not COBOL, see your COBOL system documentation on interfacing for details of when you need to use the BY REFERENCE or BY VALUE clauses.
  7. The USING phrase identifies the names of the formal parameters used by the program,

    ISO2002, function

    ISO2002MFor method for any arguments passed to it

    . The arguments passed to it are identified in the activating source element by one of the following:

    The correspondence between the two lists of names is established on a positional basis

  8. If the argument is passed by content, the activated runtime element operates as if the record in the Linkage Section were allocated by the activating runtime element during the process of initiating the activation and as if this record does not occupy the same storage area as the argument in the activating runtime element.

    If the activated runtime element is a program for which there is no program-specifier in the Repository paragraph of the activating runtime element and there is no NESTED phrase specified on the CALL statement, this allocated record is of the same length as the argument, where the maximum length is used if the argument is described as a variable-occurrence data item. That argument is moved to this allocated record without conversion. This record is then treated by the activated runtime element as if it were the argument and as if it were passed by reference.

    ISO2002MFIf the activated runtime element is one of the following:

    then this allocated record is one of:

    The argument is used as the sending operand and the allocated record as the receiving operand in one of the following:

    The allocated record is then treated as if it were the argument and it were passed by reference.

  9. If the argument is passed by reference, the activated runtime element operates as if the formal parameter occupies the same storage area as the argument.
  10. ISO2002MFIf the argument is passed by value, the activated runtime element operates as if the record in the Linkage Section were allocated by the activating runtime element during the process of initiating the activation and as if this record does not occupy the same storage area as the argument in the activating runtime element. This allocated record is exactly the same number of alphanumeric character positions in length as the argument. That argument is moved to this allocated record without conversion. This record is then treated by the activated runtime element as if it were the argument and as if it were passed by reference.
  11. At all times in the activated element, references to data-name-1

    ISO2002MF, data-name-2 and data-name-3

    are resolved in accordance with their description in the Linkage Section. If this description defines a greater number of character positions than the corresponding data item in the activating element, unpredictable results can occur. Failure to comply with this rule or exceeding the maximum allowed size of the system area for a particular run time environment may result in the system becoming catastrophically corrupt.

  12. MFWhen a program is called and a BY REFERENCE operand in the USING phrase corresponds to a parameter in the calling program, a referential connection is established and endures until control is returned to the calling program. If the program is called a second time, without any intervening cancel of the program, and that same BY REFERENCE operand does not correspond to a parameter in the calling program, then you must not reference that operand unless the STICKY-LINKAGE Compiler directive is specified.
  13. If the OPTIONAL phrase is specified for data-name-1, the OMITTED phrase may be specified as the corresponding argument; otherwise, the OMITTED phrase must not be specified as the corresponding argument.

    Note that, in COBOL, the storage for the returning item is allocated in the activating source unit. The activated element contains only a formal description in its linkage section.

  14. MFFormat 2
  15. MFIf a call prototype (program with the EXTERNAL clause in the Program-ID paragraph) contains a format 2 PROCEDURE DIVISION header and another program in the same source file includes a CALL literal statement referencing the program-name of this call prototype, then the following rules apply:
    1. If a call convention is specified in the CALL statement, it must match that specified (implicitly or explicitly) in the prototype. If no call convention is specified in the CALL statement, the call convention specified (implicitly or explicitly) in the prototype is used.
    2. The number of parameters specified in the CALL statement must equal the number of parameters specified in the prototype, except as allowed by the REPEATED phrase.
    3. For each parameter specified in the CALL statement, the following rules apply:
      1. If there is a BY REFERENCE or a BY CONTENT phrase associated with the parameter, the corresponding parameter in the prototype must be specified BY REFERENCE.
      2. If there is a BY VALUE phrase associated with the parameter, the corresponding parameter in the prototype must be specified BY VALUE.
      3. If the parameter in the CALL statement has no BY REFERENCE, BY CONTENT or BY VALUE phrase, the phrase specified (implicitly or explicitly) in the prototype is used.
      4. This rule overrides the rules that apply when no matching call prototype is found. In other words, when no call prototype is used, all parameters up to the first BY phrase are treated as if BY REFERENCE were specified and all parameters after any BY phrase, that do not themselves have an explicit BY phrase, use the last one in effect. However, when a matching call prototype is found, its definitions for the BY phrases take precedence.
      5. If the parameter in the prototype is of class numeric, or it is a pointer or index data-item, then the parameter in the CALL must have the same data definition.
      6. If the parameter in the prototype is of class alphanumeric, the parameter in the CALL must also be of class alphanumeric and be at least as long as the parameter in the prototype.
      7. If ANY is specified in the prototype, the parameter in the CALL statement can be of any class.
    4. If the CALL statement includes the GIVING or RETURNING clause, the prototype must also include the clause, and vice versa. The data definition of the data item specified in the CALL must be the same as that of the data item specified in the prototype.
    5. The DELIMITED BY SIZE phrase in the prototype can be used only for alphanumeric parameters. In this case, the corresponding parameter in the CALL statement is moved to an implicitly allocated data area, and a binary 0 (x"00") character is placed immediately following this copy of the data. If the BY SIZE phrase is omitted, the corresponding parameter in the CALL statement is moved to an implicitly allocated data area, and a binary 0 (x"00") character is placed immediately following the last non-space character in the copy data. The intention is to help in interfacing to languages such as C, which use null terminated text strings.
    6. The REPEATED phrase indicates that there must be at least integer-1 and no more than integer-2 repetitions of the final parameter. If integer-1 TO integer-2 is not specified, integer-1 is taken as 0 and integer-2 as infinite.