Generating sequence numbers using Stage variables

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

yaminids
Premium Member
Premium Member
Posts: 387
Joined: Mon Oct 18, 2004 1:04 pm

Generating sequence numbers using Stage variables

Post by yaminids »

Hello friends,

Can someone please help me with the generation of sequence numbers using Stage Variables?
In the begining of the job, we read the Max number from a table and want to generate a sequence based on the Max number
For example, if the Max number is 100 then we are interested in generating a sequence starting from 101

Any help would be highly appreciated
Thanks
Yamini
sasi_kumarreddy
Participant
Posts: 27
Joined: Thu Aug 25, 2005 6:33 am

Re: Generating sequence numbers using Stage variables

Post by sasi_kumarreddy »

Hi,

Take a stage variable v, assign a value to it i.e in u r case max number. Take another variable v1 and in the derivation set v1=v+1.
then use v1 for u r sequence. i guess this will work.

If not experts can correct me...
SASI
yaminids
Premium Member
Premium Member
Posts: 387
Joined: Mon Oct 18, 2004 1:04 pm

Re: Generating sequence numbers using Stage variables

Post by yaminids »

Hi Sasi,

Unfortunately it didn't work. Instead of incrementing the sequence by 1 the second variable just added 1 to the first variable(Max number)

Yamini
loveojha2
Participant
Posts: 362
Joined: Thu May 26, 2005 12:59 am

Re: Generating sequence numbers using Stage variables

Post by loveojha2 »

yaminids wrote:Hi Sasi,

Unfortunately it didn't work. Instead of incrementing the sequence by 1 the second variable just added 1 to the first variable(Max number)

Yamini
If @INROWNUM=1 then v+1 Else v1+1 to v1 should work here.
Success consists of getting up just one more time than you fall.
Andal
Participant
Posts: 124
Joined: Thu Dec 02, 2004 6:24 am
Location: Bangalore, India

Post by Andal »

Routine KeyMgtGetNextValue will generate the Sequence numbers. Then why you want to do it manually.
Rgds
Anand
yaminids
Premium Member
Premium Member
Posts: 387
Joined: Mon Oct 18, 2004 1:04 pm

Generating sequence numbers using Stage variables

Post by yaminids »

Hi Anand,

As you might know that the routine KeyMgtGetNextValue will generate the sequence starting from a fixed value. I am interested in generating the sequence starting from a value which is determined during the job's execution

Yamini
yaminids
Premium Member
Premium Member
Posts: 387
Joined: Mon Oct 18, 2004 1:04 pm

Re: Generating sequence numbers using Stage variables

Post by yaminids »

If @INROWNUM=1 then v+1 Else v1+1 to v1 should work here.
Thanks a lot for your help. It worked!

Yamini
prasad v
Participant
Posts: 174
Joined: Mon Mar 30, 2009 2:18 am

Post by prasad v »

Hi yamini,

Can you please tell me how it works.

Actually i tried it and it has loaded only two record and then it is giving Unique constraint violation since job is trying to load duplicate sequence number.

We have created two Stage variables and in the out put column. we have derived
If @INROWNUM=1 then v+1 Else v1+1
like this.
nani0907
Participant
Posts: 155
Joined: Wed Apr 18, 2007 10:30 am

Post by nani0907 »

@inRownum system variable works correctly only if the execution mode is sequential.duplicates are genertaed bcoz it the job is running on multiple nodes.
thanks n regards
nani
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

This is a server job.

I would not bother with stage variables at all. I would pass in the maximum value as a job parameter and use the expression

Code: Select all

jpMaxKeyValue + @INROWNUM
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
reddy1982
Participant
Posts: 3
Joined: Thu Apr 22, 2010 12:24 am
Location: bangalore

Post by reddy1982 »

ray.wurlod wrote:This is a server job.

I would not bother with stage variables at all. I would pass in the maximum value as a job parameter and use the expression

Code: Select all

jpMaxKeyValue + @INROWNUM
...
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Hello? Is there someone there? :?

Hmmm... could have sworn I heard something...
-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 »

If you track back far enough in history, there's a song called "Little Sir Echo".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
qutesanju
Participant
Posts: 373
Joined: Tue Aug 26, 2008 4:52 am

Post by qutesanju »

if you dont want to use stage variable you can go for SEQUENCE in oracle or IDENTITY in M/S SQL SERVER
Abhijeet1980
Participant
Posts: 81
Joined: Tue Aug 15, 2006 8:31 am
Location: Zürich
Contact:

Post by Abhijeet1980 »

Yep, Agree to Ray's answer. No need to reinvent the wheel.

:idea:

-Abhijit
Post Reply