Tuesday, 12 August 2014

COBOL DELETE Statement || DELETE Statement in COBOL with Example.

Holla, welcome to another exciting tutorial on "DELETE Statement in COBOL or COBOL Delete Statement". In this COBOL tutorial, you'll learn the basics of the COBOL Delete statement and its uses with an example. Let's begin our tutorial with an introduction to COBOL Delete Statement. 

Introduction. 

File/Database handling is one of the crucial parts of any enterprise application. Adding or deleting a record from a file or database is a very important operation. In COBOL, the DELETE statement is used to remove records from the file. If you want to remove the record from the database then you need to use the DELETE SQL statement.

COBOL DELETE Clause. 

The DELETE Clause in COBOL is generally used to delete records from the index file. You cannot delete records from the flat file.

COBOL Delete Syntax:

 DELETE file-name RECORD
       [INVALID KEY imperative-statement-1]
       [NOT INVALID KEY imperative-statement-2]
[END-DELETE]

To delete records from the index file, you need to open the index file in the desired mode i.e. I-O mode (input/output mode).

The records should be read from the index file based on the KEY. The deleted comment can be issue to drop the record from the file after accessing the record from the file.

DELETE statement is used to delete or erase a record from the Index file. A record should be read successfully before issuing a DELETE command. 
To delete a record from an index sequential file, the file must be opened in the I-O mode. If the access mode is sequential, then the INVALID KEY phrase should not be specified. Instead, the last I/O statement executed on the file must be a successful READ statement for the record specified.
If the file is open in RANDOM or DYNAMIC mode, then the record should be accessed by using the RECORD KEY. You should never specify the INVALID KEY parameter as this use when record not found in the file.


DELETE Statement in COBOL with Example.

Let's look at an example for a better understanding of the COBOL DELETE Clause. In this example, you have a COBOL program i.e. PGMCB01, this is a maintenance program that drops records from EMP File. The program following three basic steps to drop the record from the file.

  1. The program read record from an employee list file.
  2. Read a record from the EMP file based on KEY i.e. EMP-ID. 
  3. If the read is successful then issue COBOL DELETE command to drop record from the file and read the next record from the file. 
  4. Follow the loop until the last record. 
Refer flow diagram below: 
COBOL DELETE Clause
Mainframe Forum COBOL DELETE Clause.

Example: 

Conclusion: 

Finally, this marks an end to our today's tutorial on 'DELETE Statement in COBOL'. You have learned, the basics terminology of using the COBOL DELETE statement. Please don't forget to leave your feedback and do share this tutorial with your friend.


Tags: #COBOL #CICS #JCL #Mainframe-forum.
Linkedin: Mainframe-Forum || Facebook: Mainframe-forum

No comments:

Post a Comment

New In-feed ads