Generates unique values

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
puli.reddy
Participant
Posts: 28
Joined: Wed Jan 11, 2006 8:29 pm
Location: Singapore
Contact:

Generates unique values

Post by puli.reddy »

Hi All,

I want to populate a table with single column which should contain values from 1 to 100. I can use dummy source file as follows...
Dummy
---------
X

Thanks in advance
Thnaks and Regards,
AnjiReddy.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Anji,

what is your question?

If you have a dummy file or any file for that matter, you could use a DataStage job with a single transform stage that uses the internal value @INROWNUM to generate a sequence of values to be written to the output file.
puli.reddy
Participant
Posts: 28
Joined: Wed Jan 11, 2006 8:29 pm
Location: Singapore
Contact:

Post by puli.reddy »

Lets assume my source file is Dummy.txt which contains only one row and column. MY expected output should contain a single column and 100 rows.
Source
-------
X
Target
------
1
2
3
.
.
.
100
How can we get such values by using server job?
Thnaks and Regards,
AnjiReddy.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Since your source file has nothing at all to do with the output file why not approach the matter differently. Take a dummy source file with more rows than you want to generate and read it in a simple job. Ignore any columns from that source file, in your transform stage just set the output column value to "@INROWNUM" and put a constraint on the transform that limits the number of rows output; e.g. "@INROWNUM <= 100".
puli.reddy
Participant
Posts: 28
Joined: Wed Jan 11, 2006 8:29 pm
Location: Singapore
Contact:

Post by puli.reddy »

Thanks for your reply, I tried that way. I want to know more about usage of staging variables! Can't we achieve such loops by using staging variables?

Thanks once again
Thnaks and Regards,
AnjiReddy.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Stage variables are computed for each row; so there is no additional looping possible with them use in the normal way. Since a sequential file is in reality just a long string with one or two special characters that denote new lines (either <cr> or <cr><lf>) you could always put together your own string that contains these line markers and, with one write statement, end up creating more than one line in the output file. You could do this string buildup in a user-written routine, but it is simpler and more understandable to solve it in the way already mentioned in this thread.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ArndW wrote:Since your source file has nothing at all to do with the output file why not approach the matter differently. Take a dummy source file with more rows than you want to generate and read it in a simple job. Ignore any columns from that source file, in your transform stage just set the output column value to "@INROWNUM" and put a constraint on the transform that limits the number of rows output; e.g. "@INROWNUM <= 100".
You do realize the 'dummy source file' is completely unnecessary here, yes? :P

All you need is a Transformer and the output, whatever that may be. Declare a dummy stage variable so the job will compile but you don't even need to use it. The same constraint and output derivation will be fine.

Basically, a setup that like can be used to generate all kinds of data. I've used it to generate test data in the past, for example. Make sure you have a constraint to limit the output rows and it will keep going and going and going... :wink:

Seem to remember this technique being call 'Markov Chaining' or some such.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I had completely forgotten about that! Much easier, and caters for any file sizes as well. Thanks!
Post Reply