How to generate sequence no

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
sivap
Participant
Posts: 14
Joined: Tue Oct 26, 2004 8:13 am

How to generate sequence no

Post by sivap »

Hi

I want to generate a sequence no staring from 1. How to do that?

SeqFile -------> Xfrm -------> HashFile.

After completion this job, I want to generate one more seq no in second job i.e max no in the first job+1.

Thanks and Regards
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You must keep knowledge of where the first job left off. The easiest way is to design so that this is kept in a file (text file or hashed file). Before the first run, initialize the value in this file to 0. From your job, maintain your sequence however you like. Create an output link that passes only the sequence value into an Aggregator stage, and derive the Last value of it, which you write to your storage location. The job picks up the starting value from the storage location.

Or you can leverage the SDK routines, such as KeyMgtNextValue, which do exactly what I've described above. Why reinvent the wheel?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sivap
Participant
Posts: 14
Joined: Tue Oct 26, 2004 8:13 am

Post by sivap »

ray.wurlod wrote:You must keep knowledge of where the first job left off. The easiest way is to design so that this is kept in a file (text file or hashed file). Before the first run, initialize the value in this file to 0. From your job, maintain your sequence however you like. Create an output link that passes only the sequence value into an Aggregator stage, and derive the Last value of it, which you write to your storage location. The job picks up the starting value from the storage location.

Or you can leverage the SDK routines, such as KeyMgtNextValue, which do exactly what I've described above. Why reinvent the wheel?
Thank ray

I tried with KeyMgtNextValue , but i am gettig starting value 687 ,2124,...
but i want starting value with 1 to n(no of rows in the sorce file).when ever i run this job the no should get 1 to n. which is best way to do it?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

sivap wrote:i want starting value with 1 to n(no of rows in the sorce file).when ever i run this job the no should get 1 to n. which is best way to do it?
:? Not sure why you'd want it to always start over at 1 each time, but if you do there's an easy way to do that: the @INROWNUM System Variable. This tracks the record number coming into any given transformer, so it will 'number' all of the records from 1 to n. You can then use that as the 'surrogate'.

FYI, There is also an @OUTROWNUM as well.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You've changed your mind! :roll:

In your first post you specified "After completion this job, I want to generate one more seq no in second job i.e max no in the first job+1." That's the solution I provided.

To begin from 1 each time, you can use @INROWNUM or @OUTROWNUM as Craig suggested, or reset the sequence name used by KeyMgtNextValue. Search the forum for how to accomplish this using a before-stage subroutine.
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