Looping through a range of dates

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
shankar_ramanath
Premium Member
Premium Member
Posts: 67
Joined: Thu Aug 09, 2007 7:51 pm

Looping through a range of dates

Post by shankar_ramanath »

I have a requirement to increment date values where the date is in the format YYYYMMDD.

I have created a BASIC routine that achieves this functionality. For example, when I pass in a value of 20090531 I get an output of 20090601.

The use case scenario is that I would be provided with a range of dates in the input via two job parameters: FromDate and ToDate. I need to call a job activity for each date between FromDate and ToDate. For example, if the value of FromDate is 20090531 and the value of ToDate is 20090602, the job activity would be call thrice:once for 20090531, again for 20090601 and for 20090602.

I started working with the Start Loop activity but I could not achieve the desired functionality. I read through the forums and I thought that I could achieve this using a UserVariable stage. However, I cannot because I do not know where to provide the value of the output provided by the routine.

I could not use the value in "Step" in Start Loop activity. If I do this and provide a value of FromDate=20090531 and ToDate=20090602, the looping is not effected because 20090531 + 20090601 > 20090602. I could use it in the parameter for the Job Activity, but the result is not desired. If I use, Start_Loop_Activity.$Counter as the argument, with FromDate=20090531 and ToDate=2009602 and Step=1, the loop is repeated for 20090531, 20090532 and so on although the argument to the job activity is 20090601 always.

I would appreciate your help!

Many thanks
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The counted loop is only for integers. You may wish to convert your dates upstream to an internal, or Julian, format.
Last edited by ray.wurlod on Fri May 08, 2009 2:26 am, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
datastage_learner
Participant
Posts: 15
Joined: Thu May 07, 2009 9:50 pm

Post by datastage_learner »

calculate the total no. of days and run loop activity counter for total no. of days that you get. That may solve your issue.
Thanks,
DS_Learner
shankar_ramanath
Premium Member
Premium Member
Posts: 67
Joined: Thu Aug 09, 2007 7:51 pm

Post by shankar_ramanath »

[quote="datastage_learner"]calculate the total no. of days and run loop activity counter for total no. of days that you get. That may solve your issue.[/quote]

The issue with this approach is that the date is of a non-standard format and hence needs conversion.

I will work on Ray's suggestion.

Thanks all!
shankar_ramanath
Premium Member
Premium Member
Posts: 67
Joined: Thu Aug 09, 2007 7:51 pm

Post by shankar_ramanath »

Thanks Ray! I could use IConv and OConv to perform the looping

1. I used two user variables

fromdate = Iconv(FromDate,"D YMD")
todate = Iconv(ToDate,"D YMD")

2. Used a Start Loop (sa) to loop from "fromdate" to "todate" with Step=1.

3. Used OConv to retrieve the date value when calling the job activity
Trim(Oconv(sa.$Counter,"D YMD[4,2,2]")," ","A")
Post Reply