MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Query on DB2 commit

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
shashi0505
Beginner


Joined: 20 Jun 2005
Posts: 7
Topics: 4

PostPosted: Wed Jan 11, 2006 8:59 am    Post subject: Query on DB2 commit Reply with quote

Hi,

Suppose I have a main module having a number of Insert/update SQL's.
The main module calls a submodule which too has number of Insert/update SQL's. I have not specified COMMIT anywhere in either of thse modules. Now, suppose after a successfull call to the submodule, my main module abbends, will the updates/inserts in made in my submodule be refelcted, i.e commited?

Also, does DB2 ever automatically commit data after say N number of records, even if I havent specified COMMIT in the program?

Thanks in advance,
shashi
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Wed Jan 11, 2006 9:25 am    Post subject: Reply with quote

shashi0505,

A successful completion of the program Commits all the data. If your Submodule inserted/updated and completely succesfully returning to the main module then your inserts/updates in subprogram are committed.

Quote:

Also, does DB2 ever automatically commit data after say N number of records, even if I havent specified COMMIT in the program?


No. A commit is done after the successful completion of the program.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shashi0505
Beginner


Joined: 20 Jun 2005
Posts: 7
Topics: 4

PostPosted: Thu Jan 19, 2006 10:39 am    Post subject: Reply with quote

Hi Kolusu,

Thanks for your early reply. But I seem to have one more problem !!

My subprogram abends after inserting 3 records with sqlcode -803 for the 4th record.
But I find that the 3 previous records inserted are getting reflected in my database. Also, an update I made in my main calling module is also getting reflected.

Since I have not specified COMMIT anywhere in both of my programs, any idea how this can happen?

& what can I do to stop this from happening ?

Thanks in advance,
Shashi
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Thu Jan 19, 2006 10:58 am    Post subject: Reply with quote

Quote:

My subprogram abends after inserting 3 records with sqlcode -803 for the 4th record.



Did you abend in the subprogram itself or did you abend in main program after the call statement.

If you abended in the subprogram itself then a ROLLBACK must have taken place. But if you abended in the main program , then the first 3 rows be committed as the subprogram successfully completed.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shashi0505
Beginner


Joined: 20 Jun 2005
Posts: 7
Topics: 4

PostPosted: Thu Jan 19, 2006 11:05 am    Post subject: Reply with quote

Hi,

Thanks for your reply.

The whole problem is, my subprogram had abended(the call even did not return back to my main module), but still data stands commited. I am not able to undersatnd how it can happen. Also, the wierd thing is my update made in main module before the call to submodule also is getting commited !!!

Just out of a wild guess, has it anything to do with my Bind options?

Thanks,
Shashi
Back to top
View user's profile Send private message
Sarangadhar
Beginner


Joined: 14 Oct 2004
Posts: 130
Topics: 43
Location: virtual village

PostPosted: Thu Oct 19, 2006 8:54 pm    Post subject: Reply with quote

different requirement:
I wanted to commit all at once, only if the transactions done in program and subprogram are successful.

program1:
some transactions..
call subroutine1
end of program1


subroutine1
transactions
commit (will this commit commits the transactions in main program also?)
end of subroutine1


if not possible, can you tell me the way?
_________________
Thanks
Back to top
View user's profile Send private message
nagasadhu
Beginner


Joined: 08 Jul 2006
Posts: 17
Topics: 6

PostPosted: Thu Nov 02, 2006 11:37 am    Post subject: Reply with quote

When a plan which updates or inserts is executed DB2 performs temporary locks on the corresponding page and this accumulates as the control passes from the main to sub prog. The commit is performed only upon the succesful completion of the application program that executes the plan. In case the main or the sub program abends all the locks are released and the rollback takes place.

This is my understanding of the process. Kindly correct if mistaken.
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Thu Nov 02, 2006 2:09 pm    Post subject: Reply with quote

nagasadhu, you came as close as anyone.

I would use the words Task and Logical-Unit-of-Work (LUOW, UoW).

Within a task (one pgm, or one CALLing several sub-modules) there is something called Unit-of-Work - the amount of activity on a resourse (DB2 in this case) accomplished between start of activity and/or COMMITs/ROLLBACKS.

Depending on how a DB2 application is invoked
  • thru a test environment - xpeditor,z.B.
  • JCL
    • one of the IJKnnT's
    • a control/main module which CALLs a module to affect the CONNECT to the resourse

COMMITs/ROLLBACKs are performed against the last Unit-of-Work at End-of-Task if no explicit COMMIT/ROLLBACK was executed during the task against the last Unit-of-Work.

Is the poster sure, that before testing, his test tables were initialized to remove the effects of the last test session?

Regardless if you are beating on 4 DB2 Tables in 4 sub-modules or only one DB2 Table, a COMMIT or ROLLBACK issued against the current Unit-of-Work, will affect all DB2 Tables.

In the case of multiple resources (DB2 and MQS), you can connect to RRS which will control the syncronization of unCOMMITed UPDATEs between DB2 and MQS. RRS will make the COMMIT/ROLLBACK to the Unit-of-Work (includes DB2 and MQS activity) for the Task.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
nagasadhu
Beginner


Joined: 08 Jul 2006
Posts: 17
Topics: 6

PostPosted: Sat Nov 04, 2006 10:41 am    Post subject: Reply with quote

I think sashi0505 problem was with his ACQUIRE and RELEASE bind option. Anyways thats a pretty old post.
And sarangadher , the commit will be performed for all operations.
Back to top
View user's profile Send private message
nagasadhu
Beginner


Joined: 08 Jul 2006
Posts: 17
Topics: 6

PostPosted: Fri Nov 17, 2006 3:48 am    Post subject: Reply with quote

Hi
A little more clarification needed

1) If I execute
LOCK TABLE <NAME> IN EXCLUSIVE MODE;
UPDATE1
COMMIT1
UPDATE2
COMMIT2

Will the explicit lock on the table remain after COMMIT1?
Do I have to execute a seperate lock for COMMIT2, considering that both updates are on the same the same table?

Rgds
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Fri Nov 17, 2006 6:27 am    Post subject: Reply with quote

I don't understand why you are explicitly issuing an exclusive lock on the table. Are you attempting to prevent any other task from accessing the table?

If after an update you receive a 000 sql return code, you have an exclusive lock. Depending upon your lock options (page, row, etc.. these are designated at create table time) you will lock a page or a row. Until you issue a commit or rollback, the locked space in your table (whatever the locked space is) is exclusive. Another task can read the 'locked' area with the 'UR' option.

unless you have a long wait time (few seconds is long) between updates, you should not commit after every update (unless you are making mass updates); commits take a tremendous amount of DB2 resources. If it is a batch task, every 1000 or so (again, depends upon the effect of your update) updates then a commit. In CICS environment, explicit commits are not usually wanted because in CICS your updates should be minimal. If you are misusing CICS to accomplish mass updates, then you are actually 'batching' CICS, thus you need to issue period explicit commits to release resources.

Waiting for end of task to issue the commit (not explicit) means you do not know (within your program) is the commit actually resulted in a 000 sql return code.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
nagasadhu
Beginner


Joined: 08 Jul 2006
Posts: 17
Topics: 6

PostPosted: Mon Nov 20, 2006 12:58 pm    Post subject: Reply with quote

Thanks for the details. I was encountering a Lock escalation condition for mass updates. Sorted it out alright. Thanks again
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group