File nane with date

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

Kshitij Rawat
Participant
Posts: 68
Joined: Wed Jan 10, 2007 11:24 pm

File nane with date

Post by Kshitij Rawat »

Hi All,

I want to add current date in a file name.
For example my file name is user_records.csv
But my client want to add sysdate with this file name
Suppose sysdate is 20080417 the my file name would be "user_records_20080417"

I know with the help of Unix script we can do it ...
But is there any way in DataStage(PX or Server job) so that I can do it without Unix Shell script....

Waiting for your reply.
:)
ETL DEVELOPER

Watch The Time Cycle, You Will Have All Answers.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Yes, but it involves writing an after-job subroutine. You may as well use ExecSH as the after-job subroutine to execute a UNIX mv command.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Kshitij Rawat
Participant
Posts: 68
Joined: Wed Jan 10, 2007 11:24 pm

Post by Kshitij Rawat »

ray.wurlod wrote:Yes, but it involves writing an after-job subroutine. You may as well use ExecSH as the after-job subroutine to execute a UNIX mv command. ...

Thanks you very much for your help Sir.
ETL DEVELOPER

Watch The Time Cycle, You Will Have All Answers.
jhmckeever
Premium Member
Premium Member
Posts: 301
Joined: Thu Jul 14, 2005 10:27 am
Location: Melbourne, Australia
Contact:

Post by jhmckeever »

If your concern with the Unix option is that you don't want another 'asset' to have to manage outside the DataStage environment then couldn't you just supply the 'script' in the filename specification?

E.g. Something like ...

Code: Select all

MyFilename_`date +%Y%m%d-%H%M%S`.txt
I've been working in a purely PX environment for quite some time and don't remember if this will work in server - so apologies in advance if it's not appropriate to your environment.

John.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It's entirely appropriate to server (on UNIX).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jhmckeever
Premium Member
Premium Member
Posts: 301
Joined: Thu Jul 14, 2005 10:27 am
Location: Melbourne, Australia
Contact:

Post by jhmckeever »

Jolly good.

Ray - Let me know if you're ever running a "Parallel to Server" transition class! ;-)

John.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Interesting question. I wonder what the demand would be.
:)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ds_developer
Premium Member
Premium Member
Posts: 224
Joined: Tue Sep 24, 2002 7:32 am
Location: Denver, CO USA

Post by ds_developer »

You can also append a job parameter to the filename, as in:

user_records_#RUN_DATE#.csv

assuming you can set the #RUN_DATE# parameter. I do this on all my reject files.

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

Post by ray.wurlod »

Moderator: please move to parallel forum
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sinhasaurabh014
Participant
Posts: 86
Joined: Wed Apr 02, 2008 2:32 am
Location: Bangalore

Post by sinhasaurabh014 »

answered....just repeating..in case you may have 4gotten
use #DSJobStartDate# macro in the filename.
eg. c:\data\target_file_#DSJobStartDate#.txt
only you get date as 2008_04_23 if that is acceptable.

Nice time to ask another question.....
:?: Is there some way we can create or Modify an existing DS Macro?
suren_sharma06
Participant
Posts: 2
Joined: Tue Feb 19, 2008 4:40 pm

Re: File nane with date

Post by suren_sharma06 »

Kshitij Rawat wrote:Hi All,

I want to add current date in a file name.
For example my file name is user_records.csv
But my client want to add sysdate with this file name
Suppose sysdate is 20080417 the my file name would be "user_records_20080417"

I know with the help of Unix script we can do it ...
But is there any way in DataStage(PX or Server job) so that I can do it without Unix Shell script....

Waiting for your reply.
:)

Hi all,

Even my client need the file with date as mentioned above, however he needs version number also.

For example, the output file format should be FILENAME_DD_MM_YYYY_XX
where XX is version number.

If due to some reason job is run twice a day, the file should have XX values as 01 for the first time and 02 for the second time.

Even the client is specific for date format too.

Please help !!
Surendra Kumar Sharma
jhmckeever
Premium Member
Premium Member
Posts: 301
Joined: Thu Jul 14, 2005 10:27 am
Location: Melbourne, Australia
Contact:

Post by jhmckeever »

Using the 'script' approach I outlined previously you can specify your own date format. E.g. DD_MM_YYYY would be ...

Code: Select all

MyFilename_`date +%d_%m_%Y`.csv
What are the criteria for incrementing the version number? Every job run? If so, you could store the value in an environment variable and use a before-Job ExecSH to increment it ...

Code: Select all

MYVAL=`expr $MYVAL + 1`
Then refer to that environment variable in your filename specification:

Code: Select all

MyFilename_`date +%d_%m_%Y_$MYVAL`
There are other approaches which I'm sure other posters will provide if needed.

John.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
suren_sharma06
Participant
Posts: 2
Joined: Tue Feb 19, 2008 4:40 pm

Post by suren_sharma06 »

jhmckeever wrote:Using the 'script' approach I outlined previously you can specify your own date format. E.g. DD_MM_YYYY would be ...

Code: Select all

MyFilename_`date +%d_%m_%Y`.csv
What are the criteria for incrementing the version number? Every job run? If so, you could store the value in an environment variable and use a before-Job ExecSH to increment it ...

Code: Select all

MYVAL=`expr $MYVAL + 1`
Then refer to that environment variable in your filename specification:

Code: Select all

MyFilename_`date +%d_%m_%Y_$MYVAL`
There are other approaches which I'm sure other posters will provide if needed.

John.
The job is schedule to run everyday. So idealy there will be only one version per day. But if due to some reason, you run the job twice a day, then it should create second version.

For the next day. version should be set back to 01 again.

I appriciate above solution, but it would be great if somebody tells me solution without script.
Surendra Kumar Sharma
jhmckeever
Premium Member
Premium Member
Posts: 301
Joined: Thu Jul 14, 2005 10:27 am
Location: Melbourne, Australia
Contact:

Post by jhmckeever »

It might help if you told us why you don't / won't / can't use a shell-based solution.

An alternative is to construct a DSBasic routine:
- Use the system date to construct a filename mask (E.g. MyFile_DD_MM_YYYY_*)
- Take a look at the relevant directory to see if any of today's files exist yet (sort the output)
- Get the highest sequence number from today's files (if any)
- Generate the appropriate filename as your routine's return value (using highest sequence number + 1)
- Call this routine from a job sequence using a User Variables activity
- Reference the routine's variable as an input parameter to the job creating the file.

Actually you could get the latest of today's files with a combination of ls -1, sort, and head commands.

Hope your reason for avoiding the shell solution is good enough to justify all the extra effort! :-)

John.
Last edited by jhmckeever on Fri May 02, 2008 12:17 am, edited 1 time in total.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
Rubu
Premium Member
Premium Member
Posts: 82
Joined: Sun Feb 27, 2005 9:09 pm
Location: Bangalore

Post by Rubu »

ray.wurlod wrote:It's entirely appropriate to server (on UNIX).
Hi Ray,

Is this because the file name is going as a part of argument to export operator in PX?

Then, just wondering whether Server uses something like touch <file_name> for creating the target file?
Regards
Palas
Post Reply