View previous topic :: View next topic
|
Author |
Message |
cybertaurean
New User
Joined: 22 Dec 2008 Posts: 87 Location: US
|
|
|
|
Hi,
Let's say we have a table TB1 which contains the following columns -
Code: |
TB1
col_1 <- auto_number & key for this table
col_2 <- text
col_3 <- text |
Based on each row inserted into the above table, I need a row to be inserted into a dependent table TB2 -
Code: |
TB2
col_1 <- key for this table
col_2 <- should contain the value of col_1 in TB1 |
In case there is a combination of values available in TB1 (other than col_1) that can uniquely identify col_1, I could issue a fetch right after an insert to have the col_1 value moved into a ws-, for use in TB2 thereafter...
However, If I don't have key combinations in TB1, that can uniquely identify col_1, what can be done?
It seems like MS programming languages (forgive the reference ;)), provide some feature to extract the inserted autonumber -
http://www.access-programmers.co.uk/forums/showthread.php?t=165627
where they have something like -
Code: |
Set rs = db.OpenRecordset("SELECT @@IDENTITY AS LastID;") |
Is there something similar available that can be used in Cobol-DB2 modules? |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
"Select from insert" is your answer : google it
Code: |
SELECT col_1 into :hv1-num
FROM FINAL TABLE (INSERT INTO TB1 (col_2, col_3)
VALUES(:hv2-text, :hv3-text)) |
|
|
Back to top |
|
|
cybertaurean
New User
Joined: 22 Dec 2008 Posts: 87 Location: US
|
|
|
|
Thanks a bunch, GuyC!!!
Let me check this out! |
|
Back to top |
|
|
|