Skip to content

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:

  1. file-name-n is an indexed or relative file described in the FILE Section.
  2. keyname-1 is a literal or data element whose value creates the condition test for the placing of the file pointer by the START statement.
  3. statement-n is an imperative statement.

General Rules:

  1. file-name-1 must be OPEN INPUT or OPEN I-O when the START statement executes.
  2. If file-name-1 is a relative file, the key of reference is the data item named by the RELATIVE KEY phrase in the SELECT clause of the file.
  3. If file-name-1 is an indexed file, the key of reference may be either the data item(s) referenced in the RECORD KEY phrase, or the data item(s) referenced in an ALTERNATE RECORD KEY phrase.
  4. If keyname-1 is the data name referenced by the RECORD KEY phrase, then the START/READ NEXT sequence will be made on the primary key.
  5. If keyname-1 is the data name referenced by the ALTERNATE RECORD KEY phrase, then the START/READ NEXT sequence will be made on the alternate record key.
  6. 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 the KEY 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 the KEY clause specification.
  7. The INVALID KEY condition exists if the START statement is unable to place the record pointer based on the condition described.
  8. When the INVALID KEY condition exists, one of the following occurs:
    • If there is an INVALID KEY phrase in the START statement, the associated statement-list is executed, and control then passes to the next statement in the program.
    • If there is no INVALID KEY phrase in the START statement, the FILE STATUS variable of the file is updated with an error code, and control is either transferred to the DECLARATIVES, if they have been set up for this case, or the program aborts.
  9. The NOT INVALID KEY condition exists if the START 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.
Back to top