IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Regarding AutoNumber fields in DB2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
cybertaurean

New User


Joined: 22 Dec 2008
Posts: 87
Location: US

PostPosted: Fri Jun 22, 2012 12:05 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Jun 22, 2012 3:58 pm
Reply with quote

"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
View user's profile Send private message
cybertaurean

New User


Joined: 22 Dec 2008
Posts: 87
Location: US

PostPosted: Fri Jun 22, 2012 5:45 pm
Reply with quote

Thanks a bunch, GuyC!!!

Let me check this out!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Concatenate 2 fields (usage national)... COBOL Programming 2
No new posts Cobol COMP-2 fields getting scrambled... Java & MQSeries 6
No new posts Converting unpacked fields to pack us... SYNCSORT 4
No new posts Data for newly added fields not displ... IMS DB/DC 6
This topic is locked: you cannot edit posts or make replies. SUM FIELDS=NONE in reverse - Get dupl... DFSORT/ICETOOL 9
Search our Forums:

Back to Top