START Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
START Statement
The START statement provides a basis for logical positioning within a
relative or indexed file, in sequential or dynamic access mode, for
subsequent retrieval of records.
Syntax
NOTE The required relational characters '>' , '<' , '>=' , and '=' are
not underlined to avoid confusion with other symbols such as '>='
(greater than or equal to).
Parameters
file-name-1 the name of a relative or indexed file. The file
must be open in INPUT or I-O mode when the START
statement is executed.
data-name-1 for a relative file, must be the data item named
in the RELATIVE KEY phrase of the SELECT
statement for the file. For an indexed file,
data-name-1 may reference a data item specified
as a record key associated with the named index
file, or it may reference any alphanumeric data
item subordinate to the data name of a data item
specified as a record key of the named file,
provided that its leftmost character position
corresponds to the leftmost character position of
that record key data item. Data-name-1 may be
qualified.
imperative-statement-1 one or more imperative statements. The INVALID
and KEY phrase must be used in the START statement if
imperative-statement-2 no applicable USE procedure is specified for the
file.
Description
When the START statement executes, a comparison is made between a key
associated with file-name-1, and a data item. If the KEY phrase is
unused, the relational operator, "IS EQUAL TO" is assumed. The data item
used in the comparison depends upon whether the file named in the START
statement is a relative or an indexed file.
If the file is a relative file, the comparison uses the data item
referenced in the RELATIVE KEY clause of the file's SELECT statement.
This data item is always used, whether the KEY phrase is specified or
not. So, for example, the following statements cause the file position
indicator to be positioned at the fifth record of REL-FILE if REL-KEY is
the name specified in the RELATIVE KEY phrase of the SELECT statement for
the relative file REL-FILE:
MOVE 5 TO REL-KEY.
START REL-FILE.
If the file named in the START statement is an indexed file, the data
item used in the comparison depends upon whether the KEY phrase is used.
If the KEY phrase is not used for an indexed file, the primary key, that
is, the data item named in the RECORD KEY clause of the file, is used.
If the KEY phrase is used, the comparison uses the data item referenced
by data-name-1. This data item must be either a primary or alternate key
for the file, or must be a data item whose first character is the first
character of one of the keys for the file.
If the key associated with a record of an indexed file differs from the
size of the data item used in the comparison, the comparison proceeds as
though the longer of the two were truncated on the right so that its
length is equal to the length of the shorter. A nonnumeric comparison is
then performed following all the rules for such comparisons. The PROGRAM
COLLATING SEQUENCE, however, is not used for the comparison, even if it
was specified. The ASCII collating sequence is always used on an HP
computer system.
When comparison takes place for either type of file, the file position
indicator is positioned to the first logical record currently existing in
the file whose key satisfies the comparison.
If the comparison is not satisfied by any record of the file, an INVALID
KEY condition exists, the execution of the START statement is
unsuccessful, and the imperative-statement of the INVALID KEY phrase (if
specified) is executed. If the INVALID KEY phrase is not specified, then
a USE procedure must be specified and that procedure is executed. In
such a case, the position of the file position indicator is undefined.
The execution of a START statement causes the value of the FILE STATUS
data item, if any, associated with the file to be updated. Refer to
Chapter 6 , under "FILE STATUS Clause", for valid combinations of
status keys 1 and 2.[REV BEG] For more information on handling I/O
errors, see "Input-Output Error Handling Procedures" .[REV END]
Upon completion of a successful START statement for an indexed file, a
key of reference is established and used in subsequent format 1 READ
statements.
If the KEY phrase is not specified in an indexed file START statement,
the primary key is established as the key of reference. If the KEY
phrase is specified, and data-name-1 is any record key (primary or
alternate) for the file, that record key becomes the key of reference.
If the KEY phrase is specified, and data-name-1 is not a record key of
the file, then the first character of the data item contained in
data-name-1 is the same as the first character of some key for the file,
and that key becomes the key of reference.
If a START statement for an indexed file is unsuccessful, then the key of
reference and the file position indicator are undefined.
MPE/iX 5.0 Documentation