Date Transformation

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I would do it in two streams.
First Stream:
This is for the very last record as it needs to be generated. I sort and hash partition on the company code and pass it via aggregator, group by company code and get the max of date. This will give the last record for each company code. I will then pass it through a transformer where I will hard code the end date to 12/31/9999 and add 1 to EffDt to get the FromDt, and store it in a dataset.
Now we have the last record with the max start date and end date as high 9s.
Second Stream:
Again, I would sort and hash partition on the company code and pass it via transformer where bulk of the logic will be performed using stage variables. Its the classic approach of storing the previous record's key in stage variable and checking with current incoming key, if they are they match that means we are in the same group, if different, start from the begining.
Something like the following should work in your case:

Code: Select all

FrmDt : If in.ComanyCd = PrevKey then DateFromDaysSince(1,PrevEffDt) else StringToDate("01/01/1000", "%mm/%dd/%yyyy")
PrevKey : in.CompanyCd
PrevEffDt : in.EffDt
ToDate will be the incoming Effective Date.
Store this in another dataset.
Now, use the dataset from the first stream and second stream and combine them using a funnel stage. After combining, sort it again on company code. You will/should have your desired output.

What if there is only one record per company code, whats the logic then?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Post by kashif007 »

Thanks DSGURU let me work on it as you said and if I have any problem I will open this question again. Thanks for your again.
Regards
Kashif Khan
kashif007
Premium Member
Premium Member
Posts: 216
Joined: Wed Jun 07, 2006 5:48 pm
Location: teaneck

Post by kashif007 »

Thanks DSGURU let me work on it as you said and if I have any problem I will open this question again. Thanks for your help again.
Regards
Kashif Khan
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

DSguru2B wrote: What if there is only one record per company code, whats the logic then?
Without handling this, the logic is not complete. You will have to advise, what to do if a single record is present per comany code.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply