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 

Unique number generation Logic

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


Joined: 16 Sep 2004
Posts: 11
Topics: 4

PostPosted: Thu Oct 20, 2005 7:44 am    Post subject: Unique number generation Logic Reply with quote

Hi,
I have a requirment to write a cobol stored proc that needs to generate a unique number. There could be multiple instatnce of the same procedure and each one should have a unique number. This number is used to udpate some db2 tables where this field is the key.

Can anyone suggest a logic for this.

The number generated should be 9(9).
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
nagapa
Beginner


Joined: 16 Sep 2004
Posts: 11
Topics: 4

PostPosted: Thu Oct 20, 2005 8:09 am    Post subject: Reply with quote

Kolusu,
Think I have posted this in the wrong place.... I am working on the logic and looking forward for inputs from experts here...

Can I move this to other topics... I tried to edit it but cant

Regards
Nagapa
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Oct 20, 2005 8:16 am    Post subject: Reply with quote

Quote:

This number is used to udpate some db2 tables where this field is the key.


Nagapa,

why not define the field as Autogenerated in the table itself? You use the ROWID data type to uniquely and permanently identify rows in a DB2 subsystem. DB2 generates a value for the column when a row is added. You can use direct-row access so that DB2 accesses a row directly through the ROWID column. If an application selects a row from a table that contains a ROWID column, the row ID value implicitly contains the
location of the row. If you use that row ID value in the search condition of subsequent SELECT statements, DB2 might be able to navigate directly to the row.

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


Joined: 16 Sep 2004
Posts: 11
Topics: 4

PostPosted: Thu Oct 20, 2005 8:27 am    Post subject: Reply with quote

Hello Kolusu,
at the moment we have a id_table that holds 10 records with unique value. Our stored proc, pics a value (based on ur login ind, if ur ids last numeric digit is 1, take the value from line 1). and update that table with new value (increment the current value by 1).
There are a lot of users, and this logic cannot cope with volume. We get -913 quite often. We change the table from table lock to row lock. The abends have reduced but still prevails...

we are looking for a logic that could help us generate unique numbers instead of using this table.
Also we cannot go for autogenerated as this id is not the full key for other table but needs to be unique.

Thanks
Nagapa
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Oct 20, 2005 8:51 am    Post subject: Reply with quote

Nagapa,

Do you need the generated id to be incremental or just unique ? If it is just unique then you can use the TIMESTAMP field in DB2. Use the Microseconds portion timestamp field to generate the unique ID.

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


Joined: 16 Sep 2004
Posts: 11
Topics: 4

PostPosted: Thu Oct 20, 2005 9:12 am    Post subject: Reply with quote

Hi Kolusu,
I need it unique but sequential.

can we use CREATE SEQUENCE.... I have never used it before.
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming 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