Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Regarding AutoNumber fields in DB2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
cybertaurean

New User


Joined: 22 Dec 2008
Posts: 85
Location: US

PostPosted: Fri Jun 22, 2012 12:05 pm    Post subject: Regarding AutoNumber fields in DB2
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    Post subject:
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: 85
Location: US

PostPosted: Fri Jun 22, 2012 5:45 pm    Post subject: Reply to: Regarding AutoNumber fields in DB2
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Subtract the ZD fields to provide neg... Balaryan DFSORT/ICETOOL 4 Wed Oct 11, 2017 10:51 pm
No new posts Addition of two records on 2 fields amar143 SYNCSORT 8 Tue Oct 03, 2017 11:14 am
No new posts Split file based on comparsion to 2 f... Div Grad DFSORT/ICETOOL 3 Thu Jul 27, 2017 9:16 pm
No new posts How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us