Generating Sequential Keys in Datastage

PDF

These solutions work only for situations where the sequential key starting number can be reset (set to 1) at each run.

This simple method involves the system variable @INROWNUM or a stage variable. Whether this solution works depends on your schema or table definitions. When you require a system generated sequential key for a table this method will allow you to create one quickly which is reset to 1 for each run.

After you have your output columns defined open the transformer stage (double click on the transformer symbol) & open the stage variables properties box.

Opening the stage variables properties box is opened by RIGHT-clicking on the stage variables box within the transformer GUI. If your stage variables box is not displayed in the transformer press the "Show/Hide Stage variables" button on the transformer toolbar .

In the stage variables box enter a meaningful name for the variable which will contain the Sequential key & set it's initial value to 0 (zero).

Now all that is left is to use the variable in the derivation of your key field as shown below.

The process can be simplified by placing @INROWNUM in the derivation of the field in the TableOut link however, I prefer this method as these keys are often used in multiple links. The stage variable makes modification or maintenance of the key simpler & more straightforward. Experiment with the methods & select the best for your situation.

If @INROWNUM is not providing desirable results you can define the derivation of the Stage variable as shown below. Again, a simple solution which is reset to 1 each time the process is run.

 
Home IBM Datastage Generating Sequential Keys in Datastage