START Statement
The START
statement positions the file pointer of an indexed or relative file for a READ NEXT
or READ PREVIOUS
statement based on a condition that relates to the value of a KEY
of the file.
General Format:
START file-name-1
[KEY IS { EQUAL TO } keyname-1 ]
[ { = } ]
[ { GREATER THAN } ]
[ { > } ]
[ { NOT LESS THAN } ]
[ { NOT < } ]
[ { GREATER THAN OR EQUAL TO } ]
[ { >= } ]
[ { LESS THAN } ]
[ { < } ]
[ { NOT GREATER THAN } ]
[ { NOT > } ]
[ { <= } ]
[ { LESS THAN OR EQUAL TO } ]
[ INVALID KEY statement-1 ]
[ NOT INVALID KEY statement-2 ]
[ END-START ]
Syntax:
file-name-n
is an indexed or relative file described in theFILE
Section.keyname-1
is a literal or data element whose value creates the condition test for the placing of the file pointer by theSTART
statement.statement-n
is an imperative statement.
General Rules:
file-name-1
must beOPEN INPUT
orOPEN I-O
when theSTART
statement executes.- If
file-name-1
is a relative file, the key of reference is the data item named by theRELATIVE KEY
phrase in theSELECT
clause of the file. - If
file-name-1
is an indexed file, the key of reference may be either the data item(s) referenced in theRECORD KEY
phrase, or the data item(s) referenced in anALTERNATE RECORD KEY
phrase. - If
keyname-1
is the data name referenced by theRECORD KEY
phrase, then theSTART
/READ NEXT
sequence will be made on the primary key. - If
keyname-1
is the data name referenced by theALTERNATE RECORD KEY
phrase, then theSTART
/READ NEXT
sequence will be made on the alternate record key. - A successful
START
statement positions the file pointer according to the following rules:- Where the condition operand is one of the following:
EQUAL (“ =”), GREATER THAN (“>”)
,GREATER THAN OR EQUAL (“>=”)
,
the file pointer is placed at the first record that satisfies theKEY
clause specification. - Where the condition operand is one of the following:
LESS THAN (“<”), LESS THEN OR EQUAL (“<=”)
,
the file pointer is placed at the last record that satisfies theKEY
clause specification.
- Where the condition operand is one of the following:
- The
INVALID KEY
condition exists if theSTART
statement is unable to place the record pointer based on the condition described. - When the
INVALID KEY
condition exists, one of the following occurs:- If there is an
INVALID KEY
phrase in theSTART
statement, the associatedstatement-list
is executed, and control then passes to the next statement in the program. - If there is no
INVALID KEY
phrase in theSTART
statement, theFILE STATUS
variable of the file is updated with an error code, and control is either transferred to theDECLARATIVES
, if they have been set up for this case, or the program aborts.
- If there is an
- The
NOT INVALID KEY
condition exists if theSTART
statement is able to plsce the record pointer based on the condition described.
Code Sample:
...
SELECT CUSTFILE ASSIGN TO "CUSTOMER"
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY IS CUSTOMER-ID
FILE STATUS IS CUSTOMER-STAT.
...
FD CUSTFILE.
01 CUSTOMER-RECORD.
03 CUSTOMER-ID PIC 9(5).
03 CUSTOMER-NAME PIC X(20).
03 CUSTOMER-ADDR PIC X(20).
03 CUSTOMER-CITY PIC X(10).
03 CUSTOMER-STATE PIC XX.
03 CUSTOMER-PHONE PIC X(10).
...
77 CUSTOMER-STAT PIC XX.
...
MOVE 11111 TO CUSTOMER-ID.
START CUSTFILE KEY EQUAL TO CUSTOMER-ID.
START CUSTFILE KEY = CUSTOMER-ID.
START CUSTFILE KEY GREATER THAN CUSTOMER-ID.
START CUSTFILE KEY > CUSTOMER-ID.
START CUSTFILE KEY NOT LESS THAN CUSTOMER-ID.
START CUSTFILE KEY NOT < CUSTOMER-ID.
START CUSTFILE KEY GREATER THAN OR EQUAL TO CUSTOMER-ID.
START CUSTFILE KEY >= CUSTOMER-ID.
START CUSTFILE KEY LESS THAN CUSTOMER-ID.
START CUSTFILE KEY < CUSTOMER-ID.
START CUSTFILE KEY NOT GREATER THAN CUSTOMER-ID.
START CUSTFILE KEY NOT > CUSTOMER-ID.
START CUSTFILE KEY <= CUSTOMER-ID.
START CUSTFILE KEY LESS THAN OR EQUAL TO CUSTOMER-ID.
START CUSTFILE KEY LESS THAN OR EQUAL TO CUSTOMER-ID
INVALID KEY DISPLAY "INVALID KEY!" LINE 17 COL 10
NOT INVALID KEY
DISPLAY "NOT INVALID KEY!" LINE 17 COL 10
END-START.