View previous topic :: View next topic |
Author |
Message |
nagapa Beginner
Joined: 16 Sep 2004 Posts: 11 Topics: 4
|
Posted: Thu Oct 20, 2005 7:44 am Post subject: Unique number generation Logic |
|
|
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 |
|
|
nagapa Beginner
Joined: 16 Sep 2004 Posts: 11 Topics: 4
|
Posted: Thu Oct 20, 2005 8:09 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Oct 20, 2005 8:16 am Post subject: |
|
|
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 |
|
|
nagapa Beginner
Joined: 16 Sep 2004 Posts: 11 Topics: 4
|
Posted: Thu Oct 20, 2005 8:27 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Oct 20, 2005 8:51 am Post subject: |
|
|
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 |
|
|
nagapa Beginner
Joined: 16 Sep 2004 Posts: 11 Topics: 4
|
Posted: Thu Oct 20, 2005 9:12 am Post subject: |
|
|
Hi Kolusu,
I need it unique but sequential.
can we use CREATE SEQUENCE.... I have never used it before. |
|
Back to top |
|
|
|
|