Sequence generator

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
jdmiceli
Premium Member
Premium Member
Posts: 309
Joined: Wed Feb 22, 2006 10:03 am
Location: Urbandale, IA

Sequence generator

Post by jdmiceli »

Hi all,

I have a field in the target table namly row_id integer, which should hold the sequence numbers starting from 1..n for every new record (Insert records).
For ex:


Are there any builtin functions in Data Stage or any server processings?

Please let me know what would be the best approach?


Thanks much!
Bestest!

John Miceli
System Specialist, MCP, MCDBA
Berkley Technology Services


"Good Morning. This is God. I will be handling all your problems today. I will not need your help. So have a great day!"
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

You might want to look at the Routines>>sdk>>KeyMgt----KeyMgtGetNextValueConcurrent or KeyMgtGetNextValue.
Kris

Where's the "Any" key?-Homer Simpson
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The most efficient, if you want to start from 1 for each run, is to use the system variable @OUTROWNUM, since it is keeping that count in any case.

However, if you want a genuine sequence (starting again from where it left off), then either the SDK key management routines as mentioned, or a database sequence or auto-incrementing data type, can be used.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
SPA_BI
Premium Member
Premium Member
Posts: 36
Joined: Tue Aug 29, 2006 8:01 pm
Location: Melbourne

Post by SPA_BI »

ray.wurlod wrote:The most efficient, if you want to start from 1 for each run, is to use the system variable @OUTROWNUM, since it is keeping that count in any case.

However, if you want a genuine sequence (starting again from where it left off), then either the SDK key management routines as mentioned, or a database sequence or auto-incrementing data type, can be used.
Hi, you mentioned a database sequence, how would you use database sequence in datastage?
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

While inserting into the table, the value for the Sequence number column would be seq.nextval, where 'seq' is the sequence created using CREATE SEQUENCE statement.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

SPA_BI wrote:Hi, you mentioned a database sequence, how would you use database sequence in datastage?
Do NOT provide a key value from the job. Use user-defined SQL.

Code: Select all

INSERT INTO tablename (keycol, col1, col2, col3) VALUES (seqname.NEXTVAL, :1, :2, :3)
There are three columns defined in the DataStage job in this example.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jdmiceli
Premium Member
Premium Member
Posts: 309
Joined: Wed Feb 22, 2006 10:03 am
Location: Urbandale, IA

Post by jdmiceli »

Hi
I need to create rowid ( sequence numbers) into target table. i am using KeyMgtGetNextValue() function to populate rowid, which is always giving same ids. What my requirement is i need one similat to Informatica's Sequence generater transformation. is there any way we can generate id's like incrementally?

Day 1: starts with 1 and max would be 2009
Day 2: starts with 2010 and increment by 1 max would be 5545
Day 3 should start 5546

CAn some one help me to building my sequence generator logic which i mensioned above in Datastage.
Bestest!

John Miceli
System Specialist, MCP, MCDBA
Berkley Technology Services


"Good Morning. This is God. I will be handling all your problems today. I will not need your help. So have a great day!"
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

Hi John,

KeyMgtGetNextValue is the function that you need. It works exactly as you have laid out in your Day 1, Day 2, Day 3 scenario. You can take a look at the code for the routine/transform using DataStage Manager. I'm not sure what you could be doing wrong, but do note that you have to pass the same value to the function each day (I usually recommend using the table name). I have seen some new developers try to pass a number to the function.

Mike
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Or look under the surrogate keys folder of the functions I gave you. There's an ...AssignSkeyParallel function that works in blocks for parallel assignment if you call it that way (any blocksize other than 1 will fetch numbers in that block range). Shoot me an email if you have any questions.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Triton46
Charter Member
Charter Member
Posts: 83
Joined: Fri Feb 07, 2003 8:30 am

Post by Triton46 »

Is there some permissions around the function KeyMgtGetNextValue. If I run a job, they run fine, however if someone else in my group runs that job, the number is -1 (over and over).
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

-1 means "bad handle" - they are perhaps trying to test the routine rather than calling it from a job.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply