Monday 11 August 2014

COBOL START Statement | COBOL START Position Example | START statement in COBOL [COBOL start key is greater].

COBOL Start statement, START statement in COBOL

COBOL START Statement

Welcome back to today's session on "COBOL START Statement". In this session, you'll learn the basics of START statements in COBOL, followed by COBOL START statement syntax and COBOL Start statement example for better understanding. You'll also learn how to use the COBOL start key is greater than in your COBOL program. Let's get started with an introduction to the COBOL START statement.

COBOL START Statement - Agenda.

  • Introduction.
  • What is a COBOL START Statement.
  • COBOL START Syntax. 
  • How COBOL START Statement works.
  • COBOL START Example.
  • Conclusion.

Introduction.

File handling is one of the important aspects of any programming language. In COBOL you have many statements that can be used to read, write or update data into a sequential file, VSAM file, or DB2 database. COBOL START statement is one such statement that provides more control over the process to read data from the file. 

What is a COBOL START Statement?

In laymen's terms, the START statement in COBOL is used to position the pointer within an indexed or relative file to retrieve a record from the file. You must open the associated indexed or relative file in an appropriate mode (i.e. Input or I-O mode) before you issue the COBOL START command. 
COBOL Tutorial

COBOL START KEY Tutorial

The COBOL START statement enables the programmer to position the relative file at some specified point so that subsequent sequential operations on the file can start from this point instead of the beginning. 
The KEY IS phrase in COBOL START indicates how the file is to be positioned. 
The data-name in this phrase must be the data-name in the RELATIVE KEY phrase of the SELECT . . . ASSIGN . . . clause. 

When the EQUAL TO or NOT LESS THAN condition is specified, the file is positioned at the point indicated by the relative key-data item. 

When the GREATER THAN condition is specified, the file is positioned at the next relative position of the position indicated by the RELATIVE KEY data item.

COBOL START Statement Syntax.

The COBOL START statement is pretty simple and easy to understand. But, you have to be careful while using the COBOL START statement in your programs. You must clearly understand the requirement before implementing the COBOL START VERB. Let's focus on the following START statement syntax. 


COBOL Tutorial, COBOL Start statement in COBOL, COOBL START

START STATEMENT in COBOL.

  • FILE Name: You must specify the file name after the START keyword. The file details must be defined correctly in your COBOL program. 
  • KEY Phrase: When the KEY phrase is specified, the file position indicator is positioned at the logical record in the file whose key field satisfies the comparison. If the KEY phrase is not defined, KEY IS EQUAL (to the prime record key) is implied.
  • INVALID KEY: The invalid key function will be trigger if there is no record that satisfies comparison criteria. 
  • END-START phrase: is the explicit scope terminator for the COBOL START statement.

How COBOL START Statement works?

In nutshell, the START statement in COBOL is used to set a pointer before you issue a COBOL READ command to read the record from the file.  As a thumb rule, before you issue a Start statement, you must place a key value in the RECORD KEY field. Then, the Key clause of the Start statement establishes the first record to be processed. As you can see, that record can have a value that’s either equal to, greater than (i.e.  COBOL start key is greater), or equal to the value you specify. 
  

COBOL START Example. 

In the following example, 1000 is moved to item-no. The item-no is used as a primary key to read the data from the file. 
COBOL Tutorial, COBOL START Example, START Statement with COBOL

COBOL START STATEMENT EXAMPLE.

#1. COBOL Startment Statement Example: 

 IDENTIFICATION DIVISION.
*
   ....
   ....
*
 PROCEDURE DIVISION.
*
 A00-MAIN-MODULE.
     PERFORM D00-OPEN-FILE 
     PERFORM E00-PREP-KEY
     PERFORM F00-READ-FILE
     ....
     ....
     ....
  STOP RUN.
*
 D00-OPEN-FILE. 
     OPEN INPUT EMPMST.
 E00-PREP-KEY. 
     MOVE 1090     TO EMP-IND
     START EMPMST KEY IS => EMP-ID
           INVALID KEY "Input Valid Key."
     END-START. 
*
 F00-PREP-KEY.
     MOVE SPACES   TO EMP-REC
     READ EMPMST   
          AT END 'END OF FILE'
     END-READ.  
 .....
 .....
 ..... 
 

Conclusion. 

Finally, this marks an end to the COBOL START Statement. In this session, you learn the basics of the COBOL START statement. You also learn different parameters of COBOL START statement syntax followed by the COBOL Start statement example for better understanding. You also learned how to use the COBOL start key is greater than in your COBOL program.  Do check out COBOL LEVEL 88 Condition.


Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 
Mainframe Forum™

No comments:

Post a Comment

New In-feed ads