START Statement (Relative and Indexed I-O) COBOL

The START statement provides a method of setting the file position indicator for a relative or indexed file and provides a means of determining whether a record exists.

START Statement (Relative and Indexed I-O)

Note:The required relational characters >, < and = are not underlined to avoid confusion with other symbols.

file-name-1 must be the name of a relative or indexed file.

file-name-1 must be the name of a file with sequential or dynamic access.

data-name-1 or split-key-name-1 may be qualified.

split-key-name-1 and the SIZE phrase may be specified only for indexed files.

identifier-1 must refer to an elementary integer data item.

The INVALID KEY phrase must be specified if no applicable USE procedure is specified for file-name-1.

If file-name-1 is the name of a relative file, then data-name-1, if specified, must be the data item specified in the RELATIVE KEY phrase of the associated file control entry.

If file-name-1 is the name of an indexed file then data-name-1 , if specified, may reference any one of the data items specified as the record keys associated with file- name-1 or it may reference any data item of category alphanumeric whose leftmost character position corresponds to the leftmost character position of a record key data item and whose length is not greater than the length of that record key.

If ile-name-1 is the name of an indexed file, split-key-name-1, if specified, may refer to any one of the split keys specified as the record keys associated with file-name-1. file-name-1 must be open in the INPUT or I-O mode at the time the START statement is executed.

If the KEY phrase is not specified, the relational operator IS EQUAL TO is implied and, for an indexed file, the key of reference is the prime record key of the file.

The type of comparison specified by the relational operator in the KEY phrase of a START statement occurs between a key associated with a record in the file to which file-name-1 refers and a data item.

  • If file-name-1 refers to a relative file, the data item used in the comparison is the relative key associated with file-name-1.All numeric comparison rules apply.
  • If file-name-1 refers to an indexed file, the data item used in the comparison is either the prime record key associated with file-name-1 or, if the KEY phrase is specified, the data item or split key to which the KEY phrase refers. The comparison is made on the ascending key of reference according to the collating sequence of the file. If the operands of the comparison are of unequal size, comparison proceeds as though the longer one were truncated on the right such that its length is equal to that of the shorter. The size of the comparison is further modified by the SIZE phrase, if specified. All other nonnumeric comparison rules apply, except that the presence of the PROGRAM COLLATING SEQUENCE clause has no effect on the comparison.

When FIRST or LAST are specified in the KEY phrase instead of a relational operator, no comparison takes place and the value of the relative key data item for a relative file or the value of the key of reference data item for an indexed file is not used in setting the file position indicator.

For a relative file the file position indicator is modified as follows:

  • If the relational operator specifies that the key must be “equal to”, “greater than” or “ greater than or equal to” the data item, then the file position indicator is set to the lowest relative record number of a record currently existing in the file whose key satisfies the comparison.
  • If the relational operator specifies that the key must be “less than” or “less than or equal to” the data item, then the file position indicator is set to the highest relative record number of a record currently existing in the file whose key satisfies the comparison.
  • If FIRST is specified, the file position indicator is set to the lowest relative record number of a record currently existing in the file.
  • If LAST is specified, the file position indicator is set to the highest relative record number of a record currently existing in the file.

For an indexed file, the file position indicator is modified as follows:

  • If the relational operator specifies that the key must be “equal to”, “greater than” or “greater than or equal to” the data item, then the file position indicator is set to the value of the key of reference of the first logical record currently existing in the file whose key satisfies the comparison.
  • If the relational operator specifies that the key must be “less than” the data item, then the file position indicator is set to the value of the key of reference of the last logical record currently existing in the file whose key satisfies the comparison.
  • If the relational operator specifies that the key must be “less than or equal to” the data item, then the file position indicator is set to the value of the key of reference of the first record whose key equals the data item. If no record with the specified key value currently exists in the file, then the file position indicator is set to the value of the key of reference of the last logical record currently existing in the file whose key satisfies the comparison.
  • If FIRST is specified, the file position indicator is set to the lowest value of the key of reference of a record existing in the file according to the collating sequence of the file.
  • If LAST is specified, the file position indicator is set to the highest value of the key of reference of a record existing in the file according to the collating sequence of the file.

If there are no records currently existing in the file or if the comparison is not satisfied by any record currently existing in the file, an invalid key condition exists. The invalid key condition also exists if file-name-1 refers to an optional input file that is not present. When the invalid key condition exists, the execution of the START statement is unsuccessful, the file position indicator is set to indicate that no valid next record has been established, and, for indexed files, the key of reference becomes undefined.

The execution of the START statement causes the value of the file status data item associated with file-name-1, if there is one, to be updated. It does not alter either the contents of the record area or the contents of the data item referenced by the data-name specified in the DEPENDING ON phrase of the RECORD clause associated with file-name-1.

For indexed files, a key of reference is established as follows:

  • If the KEY phrase is not specified, the prime record key for the file becomes the key of reference.
  • If the KEY phrase is specified and data-name-1 or split-key-name-1 is one of the record keys of the file, that record key becomes the key of reference.
  • If the KEY phrase is specified and data-name-1 is not one of the record keys of the file, the record key whose leftmost character position coincides with the leftmost character position of the data item referenced by data-name-1 becomes the key of reference.

For indexed files, the key of reference is used to select the data item that participates in the key comparison described above, and it is used for subsequent sequential (Format 1) READ statements.

In single record locking modes, any record lock held by the run unit for file-name-1 is released upon execution of the START statement. The START statement does not obtain a record lock and does not indicate the lock status of the record that satisfies the comparison.

In multiple record locking modes, any record locks held by the run unit for file-name-1 are not released upon execution of the START statement.

SIZE Phrase

SIZE Phrase

The SIZE phrase modifies the length of the data item used in the comparison to a key associated with a record in the indexed file to which file-name-1 refers. Since there is no comparison to a data item for the FIRST and LAST options, the SIZE phrase has no effect when specified with those options. The SIZE phrase is not allowed if file-name-1 refers to a relative file.

When the SIZE phrase is omitted, the size of the data item specified in the KEY phrase, or the size of the prime record key for file-name-1 when the KEY phrase is omitted, is used as the size in the comparison described above.

When the SIZE phrase is present, integer-1 or the value of the data item to which identifier-1 refers is used as the size in the comparison described above.

integer-1 or the value of the data item to which identifier-1 refers must be greater than or equal to one and less than or equal to the length of the record key specified by the KEY phrase, if present, or the length of the prime record key for file-name-1, if the KEY phrase is omitted.

Note:Specification of the SIZE phrase overrides the size of a data item specified by data-name-1 when that data item is not a record key of the file.

INVALID KEY and NOT INVALID KEY Phrases

INVALID KEY imperative -statement-1

NOTINVALID KEY imperative -statement-2

The causes of the invalid key condition for the START statement are indicated in the preceding text. Transfer of control following the execution of the START operation depends on the presence or absence of the INVALID KEY and NOT INVALID KEY phrases. See the discussions of relative organization input-output and indexed organization input-output for additional information regarding the invalid key condition and the effect of the INVALID KEY phrases.

START Statement (Relative and Indexed I-O) Examples


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