Generate sequential number for inserts

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
johndeere
Participant
Posts: 5
Joined: Fri Oct 29, 2004 7:35 pm

Generate sequential number for inserts

Post by johndeere »

I am inserting detail records into a table. I need to generate an increasing number for each detail that relates to the same master ID. An example would be orders. Each set of order details would have a set of sequence or line numbers. Order #1 has details 1,2,3 and order #2 has details 1,2,3.

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

Post by ray.wurlod »

Welcome aboard! :D

There are several solutions to this problem. If you've already loaded the master records, then you can load a hashed file with each master key. A non-key column could store the "next value" for each master key.

Indeed, you could even load them into the SDKSequences hashed file used by the KeyMgtGetNextValue routine. This might be the easiest approach for you. The routine already exists; you would not have to write one.

You could use stage variables, detecting change in the master key value and resetting or incrementing a counter as appropriate.

You could load the detail records into a UV table normalized on the detail information and use a synthetic key (@ASSOC_ROW) to generate the detail row identifiers.

These ideas will give you something to get started.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Sunshine2323
Charter Member
Charter Member
Posts: 130
Joined: Mon Sep 06, 2004 3:05 am
Location: Dubai,UAE

Generate sequential number for inserts

Post by Sunshine2323 »

Hi! :)

I have already done this by the use of Stage Variables.

I have 2 stage Variables svChkDup and svCOUNTER

Derivation for svChkDup
IF RowProcCompareWithPreviousValue(lnkINPUT.OrderNo) THEN "Y" ELSE "N"

Derivation for svCOUNTER
IF svCHKDUP="N" THEN 1 ELSE svCOUNTER +1

Now u just have to insert svCOUNTER stage variable into the derivation for the Details No.

Hope this Helps :)
Sunshine
johndeere
Participant
Posts: 5
Joined: Fri Oct 29, 2004 7:35 pm

Post by johndeere »

Thanks for the help. I am very new to the tools and I have noever used a hash file but I will start looking at them.
I will also research stage variables.

Thanks again.
Post Reply