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.
Generate sequential number for inserts
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Charter Member
- Posts: 130
- Joined: Mon Sep 06, 2004 3:05 am
- Location: Dubai,UAE
Generate sequential number for inserts
Hi! ![Smile :)](./images/smilies/icon_smile.gif)
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![Smile :)](./images/smilies/icon_smile.gif)
Sunshine
![Smile :)](./images/smilies/icon_smile.gif)
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
![Smile :)](./images/smilies/icon_smile.gif)
Sunshine