INITIALIZE Statement COBOL

The INITIALIZE statement provides the ability to set selected types of data fields to predetermined values; for example, numeric data to zeroes, alphanumeric data to spaces, or data pointers to NULL.

INITIALIZE Statement

identifier-1 must be of class alphabetic, alphanumeric, numeric, or data pointer.

For the category data-pointer specified in the REPLACING phrase, a SET statement with identifier-2 or literal-1 as the sending operand and an item of the category data-pointer as the receiving operand must be valid.

For each of the other categories specified in the REPLACING phrase, a MOVE statement with identifier-2 or literal-1 as the sending item and an item of the specified category as the receiving operand must be valid.

The same category cannot be repeated in a REPLACING phrase.

An index data item may not appear as an operand of an INITIALIZE statement.

The data description entry for the data item referenced by identifier-1 must not contain a RENAMES clause.

General Rules

The general rules that apply to the INITIALIZE statement are as follows:

  1. The data item referenced by identifier-1 represents the receiving item.
  2. If the REPLACING phrase is specified, literal-1 or the data item referenced by identifier-2 represents a possible sending item as specified in general rule 6.
  3. The keywords in category-name correspond to a category of data as defined in the discussion of the PICTURE clause, or for DATA-POINTER, by the USAGE IS POINTER clause.If ALL is specified in the VALUE phrase, it is as if all of the categories listed in the syntax for category-name were specified.
  4. Whether identifier-1 references an elementary item or a group item, the effect of the execution of the INITIALIZE statement is as though a series of implicit MOVE or SET statements, each of which has an elementary data item as its receiving-operand, were executed.The receiving-operands of these implicit statements are defined in general rule 5 and the sending-operands are defined in general rule 6.
  5. If the category of a receiving operand is data-pointer, the implicit statement is:

    SET receiving-operand TO sending-operand

    Otherwise, the implicit statement is:

    MOVE sending-operand TO receiving-operand
  6. The receiving operand in each implicit MOVE or SET statement is determined by applying the following steps in order:
    • First, an elementary data item is a possible receiving item if:
      1. It is explicitly referenced by identifier-1; or
      2. It is contained within the group data item referenced by identifier-1.If the elementary data item is a table element, each occurrence of the elementary data item is a possible receiving-operand.
    • Second, the following data items are excluded as receiving-operands:
      1. Any identifiers that are not valid receiving operands of a MOVE statement, except data items of category data-pointer.(For example, index data items are excluded as receiving-operands.)
      2. If the FILLER phrase is not specified, elementary data items with an explicit or implicit FILLER clause.If the FILLER phrase is specified, elementary data items with an explicit or implicit FILLER clause are not excluded and may be initialized by the INITIALIZE statement.
      3. Any elementary data item subordinate to identifier-1 whose data description entry contains a REDEFINES clause or is subordinate to a data item whose data description entry contains a REDEFINES clause.However, identifier-1 may itself have a REDEFINES clause or be subordinate to a data item with a REDEFINES clause.
    • Finally, each non-excluded possible receiving-operand is a receiving item if at least one of the following is true:
      1. The VALUE phrase is specified, the category of the elementary data item is one of the categories specified or implied in the VALUE phrase, and the VALUE clause is specified in the data description entry of the elementary data item.
      2. The REPLACING phrase is specified and the category of the elementary data item is one of the categories specified in the REPLACING phrase.
      3. The DEFAULT phrase is specified or neither the REPLACING nor the VALUE phrase is specified.
  7. The sending-operand in each implicit MOVE or SET statement is determined as follows:
    • If the data item being initialized qualifies as a receiving-operand because of the VALUE phrase, the sending-operand is determined by the literal in the VALUE clause specified in the data description entry of the receiving-operand data item. If the data item is a table element, the literal in the VALUE clause that corresponds to the occurrence being initialized determines the sending-operand. For categories other than data-pointer, the actual sending-operand is a literal that, when moved to the receiving-operand with a MOVE statement, produces the same result as the initial value of the data item as produced by the application of the VALUE clause.
    • If the data item being initialized does not qualify as a receiving-operand because of the VALUE phrase, but does qualify because of the REPLACING phrase, the sending-operand is the literal-1 or identifier-2 associated with the category specified in the REPLACING phrase that matched the category of the receiving-operand.
    • If the data item does not qualify as a receiving-operand because of the VALUE or REPLACING phrases, the sending-operand used depends on the category of the receiving-operand as shown in Table.
  8. Default Initialization Values

    Default Initialization Values

  9. The order of execution of these implicit MOVE and SET statements is the order, left to right, of the specification of each identifier-1 in the INITIALIZE statement. Within this sequence, whenever identifier-1 refers to a group data item, affected elementary data items are initialized in the sequence of their definition within the group data item.For a fixed-occurrence data item, all occurrences of the affected elementary data items are initialized.For a variable-occurrence data item, the number of occurrences initialized is determined by the rules of the OCCURS clause for a receiving data item.
  10. If identifier-1 occupies the same storage area as identifier-2, the result of the execution of this statement is undefined, even if they are defined by the same data description entry.See “Overlapping Operands” on for additional information.

INITIALIZE Statement Examples


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

COBOL Topics