Hi,
There is a table T1. For each row of T1, I need to update tables T2, T3 and T4 in succession i.e if T2 update is successful, then update T3 and if T3 successful then T4 and so on. What is the shortest way to implement this logic in cobol db2 program.
thanks.
Updating Db2 tables in succession
Moderators: Kalicharan, Moderator Group
In my view, you can avoid Declaring curosr on T1. You cannot avoid multiple update statements.
UPDATE T2
SET XXXX = YYYY
WHERE ID = ( SELET ID FROM T1 )
Other ways...
You may update all three tables togther by declaring updatable view on these
tree tables (T2,T3,T4 ).
OR
write a Stored procedure to do update task and call that SP.
UPDATE T2
SET XXXX = YYYY
WHERE ID = ( SELET ID FROM T1 )
Other ways...
You may update all three tables togther by declaring updatable view on these
tree tables (T2,T3,T4 ).
OR
write a Stored procedure to do update task and call that SP.
Natarajan
Chennai
Chennai
-
- Member
- Posts: 7
- Joined: Wed Aug 12, 2009 12:05 pm
- Location: Mumbai
Please try below mthod. This is simple and good in performance point of view.
Create two triggers
trigger1- which will update table t3 after update on table t2.
trigger2 -which will update table t4 after update on table t3.
write update statement for table t2 by selecting from table t1.
the example of triggers and update statement are as below,
create trigger t2
after update of address on table2
referencing OLD as old NEW as new
FOR EACH ROW
mode db2sql
BEGIN ATOMIC
UPDATE table3 SET table3.address = new.address where table3.no = OLD.no;
END@
create trigger t3
after update of address on table3
referencing OLD as old NEW as new
FOR EACH ROW
mode db2sql
BEGIN ATOMIC
UPDATE table4 SET table4.address = new.address where table4.no = OLD.no;
END@
update table2 a set a.address =(select b.address from table1 b where b.no = a.no )@
Regards,
Anand.
Create two triggers
trigger1- which will update table t3 after update on table t2.
trigger2 -which will update table t4 after update on table t3.
write update statement for table t2 by selecting from table t1.
the example of triggers and update statement are as below,
create trigger t2
after update of address on table2
referencing OLD as old NEW as new
FOR EACH ROW
mode db2sql
BEGIN ATOMIC
UPDATE table3 SET table3.address = new.address where table3.no = OLD.no;
END@
create trigger t3
after update of address on table3
referencing OLD as old NEW as new
FOR EACH ROW
mode db2sql
BEGIN ATOMIC
UPDATE table4 SET table4.address = new.address where table4.no = OLD.no;
END@
update table2 a set a.address =(select b.address from table1 b where b.no = a.no )@
Regards,
Anand.
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page