Increment Date on a Sequential File.

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
Kel
Participant
Posts: 31
Joined: Mon May 11, 2015 3:20 am
Location: Robinsons Cybergate Tower 2
Contact:

Increment Date on a Sequential File.

Post by Kel »

Hi,

I have a sequential file which contains a date

20150812

We read it on a sequence job using execute command and pass it on to a user variable activity then to our sequence job so that our job can get its value.

My question is it is possible to increment this date and taking to account valid dates, example leap years, 30th and 31st of the month, etc., after every successful run of the job.

Advanced Thank you.
BOG
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

Control file can be overwritten in a subsequent job.

On successful completion of main job/sequence ... execute a successor job to trap 'user variable' mentioned in your post, convert string from YYYYMMDD to Date format, increment date by 1 (see DateOffsetByDays function) and then convert it back to YYYYMMDD and overwrite the control file.

However it will be a better and more robust approach to park control records in a database (rather than a sequential file) and extract them as and when needed.
Kel
Participant
Posts: 31
Joined: Mon May 11, 2015 3:20 am
Location: Robinsons Cybergate Tower 2
Contact:

Post by Kel »

Hi, Thank you for your reply rkashyap.

What do you mean by a job to trap 'user variable'? Can you please advice .

Ahm regarding as to why the control file is a sequential file rather than database I dont really know but its the requirement given to us.
BOG
FranklinE
Premium Member
Premium Member
Posts: 739
Joined: Tue Nov 25, 2008 2:19 pm
Location: Malvern, PA

Post by FranklinE »

Kel, I don't think we know enough to help you here. It comes down to what the date represents.

How is it being used? Is it a stand-in for the process date, is it the date of the last run, or is it just a check mark on a calendar?

Or something I'm missing, perhaps?

We use a process date in every cycle. Our cycle spans midnight, so sometimes we store the date in a file (control card) and use it instead of querying the current or system date. In a couple of cases it represents the last run date, and since we are business oriented it must be a business day, not a holiday or weekend day.
Franklin Evans
"Shared pain is lessened, shared joy increased. Thus do we refute entropy." -- Spider Robinson

Using mainframe data FAQ: viewtopic.php?t=143596 Using CFF FAQ: viewtopic.php?t=157872
Kel
Participant
Posts: 31
Joined: Mon May 11, 2015 3:20 am
Location: Robinsons Cybergate Tower 2
Contact:

Post by Kel »

Hi FranklinE,

Sorry if it is not clear.

We use the date on that control file as an extension to names of text files that we are going to extract.

For Example,
/path/filenameyyyymmdd.TXT
where yyyymmdd is the date from control file.

Hope this helps.
BOG
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

rkashyap wrote:On successful completion of main job/sequence ... execute a successor job to trap 'user variable' mentioned in your post, convert string from YYYYMMDD to Date format, increment date by 1 (see DateOffsetByDays function) and then convert it back to YYYYMMDD and overwrite the control file.
That would require a Parallel job just to read and increment a date in what I assume is a one record sequential file, seems a bit overkill to me. Better IMHO to write a custom routine and leverage it in the / a sequence or even after job. Date manipulation in BASIC is pretty straight forward but if you don't want to roll up your own, Ray does have a set of "Date Math" routines you can freely download from his site. Or at least he did...
-craig

"You can never have too many knives" -- Logan Nine Fingers
FranklinE
Premium Member
Premium Member
Posts: 739
Joined: Tue Nov 25, 2008 2:19 pm
Location: Malvern, PA

Post by FranklinE »

Kel wrote:We use the date on that control file as an extension to names of text files that we are going to extract.

For Example,
/path/filenameyyyymmdd.TXT
where yyyymmdd is the date from control file.
That's a good answer. I would suggest the next question: what is the significance of the date? What does it mean in the file name?

You can establish a date in other ways besides storing it in the file. I don't mean that your requirement may be questionable, but if you answer the "why" you might find simpler ways to use that date.

For example, I use the process date in file names also, mainly to keep them unique from one cycle to the next. I don't need to keep the date in a file, I just establish it (cycle date, for example) at the beginning of the cycle and propagate it to every job.
Franklin Evans
"Shared pain is lessened, shared joy increased. Thus do we refute entropy." -- Spider Robinson

Using mainframe data FAQ: viewtopic.php?t=143596 Using CFF FAQ: viewtopic.php?t=157872
Kel
Participant
Posts: 31
Joined: Mon May 11, 2015 3:20 am
Location: Robinsons Cybergate Tower 2
Contact:

Post by Kel »

Hi chullet,

Can you give me the link of the site for the "Date Math" Routines by ray so I can browse it.


Hi FranklinE,

I will have to confirm this, but my understanding is that we use this date to keep track on changes of the file.
For example:
On the FTP Server, The File is named, file.txt

Then we extract it to a sequential file as fileyyyymmdd.txt
Then we use this sequential file to other jobs.

But lets say that a row was removed on file.txt the next day.
Then on extraction from FTP to Sequential File, the file name will be
fileyyyymmdd+1.txt

-so basically what I think is the dates are used to keep track on the changes on the sequential file.

:EDIT, my explanation is so unclear. Peace.
BOG
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ray would have to supply that, if still applicable.
-craig

"You can never have too many knives" -- Logan Nine Fingers
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

Kel wrote:We read it on a sequence job using execute command and pass it on to a user variable activity then to our sequence job so that our job can get its value.
'User variable activity' can be passed to the 'new' job via job-parameters.

Though as noted, a custom Server(i.e. Basic) routine would be better suited for this task ... faster to code, compile and execute than a parallel job for a single record manipulation. For small data volumes, or for utility functions, Basic routines and server jobs usually finish before initial housekeeping of a parallel job is done.

BTW ... if this helps, code of a Basic routine to increment date is:

Code: Select all

Ans=Trim(Oconv(Iconv([i]IN_YYYYMMDD[/i],"DYMD[4,2,2]")+[i]IN_DAYS2OFFSET[/i],"D YMD[4,2,2]"),' ','A')
Return Ans
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There are Transforms in every project including MONTH.LAST. Check them out. You should be able to invoke Transforms from User Variable expressions.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply