You are on page 1of 2

COMMIT_RESTART Logic: 

COMMIT is the DB2 statement which saves the updates made to DB2 tables since the start of the
program or the last COMMIT.

It does so by physically applying the all the changes to the DB2 Log.  

When a program abends, the changes are rolled back to the last Commit / Sync point.

When is a COMMIT issued -

A unit of work is a portion of processing that gives a logical completion and helps in achieving data
integrity. The Updates done during a unit of work are saved by issuing a DB2 COMMIT. 

For Example, suppose we have an application that involved update of 2 tables which are related to
each other. And suppose the update of table1 is COMMITed and the program abends before
COMMITing the UPDATE to the other. The data in the 2 tables will no longer be synchronous. To
Achieve data integrity, we must issue a COMMIT only when the processing reaches  a logical end. 

Checkpoint-Restart Logic:

Application Programs which process large volumes of data and those that involve modification of Db2
Tables need to  incorporate a Restart Logic when a system error occurs.

This is to help in continuing the processing from the record next to the last successfully processed
row. 

 Create a DB2 table which will have

      Pgm_name

      Job_name

      Commit_Frequency

      No_of_Commits

      Checkpoint_Key

      Checkpoint_Time 

      The Unique key will be Pgm_Name, Job_Name 

    Declare 2 cursors – both with ORDER BY for the columns that form the unique index for the

    table.  One cursor will be used to do normal processing. The other cursor while restarting       

    the application  is used to reposition at the record following the last saved record . This is

    done using additional predicates like Where Key > Last_Key
   

    For every row that is fetched, processing is done, tables are updated. Then based on

    elapsed time since last commit or commit frequency, etc, COMMIT is issued

    Before every COMMIT is issued, the ckpt_restart table is updated with the Current key for

    Which processing is complete and the current timestamp.    

    If the program is restarted, it reads the key in the ckpt table and uses that in 2 nd cursor to

    Reposition. Then continues processing.

           

    After the processing  is complete for all the rows, the ckpt table keys are set to default

    Values.  

    If File inputs are used for processing, then we need to reposition the input record by saving

    the read_count in the ckpt table. And upon restart perform read in a loop till the count is >

    the read_count.

    Or else is the file is sorted on the same key that is stored in the ckpt table, we can

    Reposition to the next key. 

    If there are File outputs, they need to be have a disp=Mod in the jcl to continue appending The
records.

You might also like