- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implementation of restart logic in a COBOL-DB2 program
Problem: A COBOL-DB2 program takes the data from an input file having 1000 records and inserts the data in a DB2 table. The program failed after 432nd record. How will you implement restart logic?
Solution
The restart logic can be implemented in a COBOL-DB2 program by fixing a commit frequency. If we choose a commit frequency of 100, then the following steps need to be performed:
- Declare a variable for a counter, say WS-COUNT.
- Place a loop in which we will read the record from the file and insert it in a database. Increment the counter WS-COUNT by one each time a record is inserted successfully.
- As soon as WS-COUNT reaches the commit frequency 100, we will write the last inserted record key (key field) in a separate output file, initialize WS-COUNT and fire COMMIT statement. Make sure to open this separate output file in I/O mode so that we can REWRITE the record each time.
- Repeat the above process for each 100th record inserted, i.e., 100th, 200th, 300th and so on.
- When the last record i.e. 1000th record is inserted successfully we will empty the output file. However, if the program appends due to any reason the output file will have the last successfully inserted and committed record.
- At the beginning of the program include a logic to check if the output file is empty or non-empty. If the file is empty, then the start will be considered as a fresh start and if the file is non-empty then we will consider it as a program restart after an append.
- In case of restart, the output file already has the last inserted/committed record. We need to simply read the input file in loop and compare its key with the output file. Once the key matches, we need to start processing the records and insert them in the database.
- Related Articles
- Implementation of a table level locks in a COBOL-DB2 program during program execution
- Implementation of a table level locks in a COBOL-DB2 program during SQL execution
- Steps involved in compilation of a COBOL-DB2 program
- How to precompile a COBOL-DB2 program?
- Purpose and usage of SAVEPOINT in COBOL-DB2 program
- Impact of database downtime on the COBOL-DB2 program
- How to execute a COBOL-DB2 program PROGA of plan PLANA?
- How to store a NULL value in a particular column of a DB2 table using COBOL-DB2 program?
- How can you revert all the DB2 table changes done in a COBOL-DB2 program?
- How NON-REPEATABLE READ & PHANTOMS impact functioning of a COBOL-DB2 program?
- Implementation of common error-trapping logic for all SQL statements in program
- Behaviour of a COBOL-DB2 program when number of locks exceed the limit
- Implementation of Boolean Functions using Logic Gates
- How to use SQLCA in a COBOL-DB2 program? What is the purpose of SQLCA?
- What is the purpose and usage of “WHERE CURRENT OF” clause in a COBOL-DB2 program?

Advertisements