Append date with file
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 73
- Joined: Wed Jun 28, 2006 3:27 pm
- Location: NJ
Append date with file
I have ran the job and the file test.txt is created. Now I want to append current date in format :
test_MMDDYYYY.txt
Is there any way in Datastage or will have to write a shell script ? And if a shell script how shall i proceed ?
Thanks
test_MMDDYYYY.txt
Is there any way in Datastage or will have to write a shell script ? And if a shell script how shall i proceed ?
Thanks
"Nobody is expert in Everything,
But Everybody is expert in Something."
But Everybody is expert in Something."
One way I can recollect is Pass the name of the file as a parameter. Then, in the Jobsequence include this Job and for the FILENAME parameter, use the expression editor within the Jobactivity stage to append the date to the file name and you should be fine.
You can also use DSMacros for defining the file names where you can append the date. You might want to take a look at the help.
IHTH.
You can also use DSMacros for defining the file names where you can append the date. You might want to take a look at the help.
IHTH.
Kris
Where's the "Any" key?-Homer Simpson
Where's the "Any" key?-Homer Simpson
-
- Participant
- Posts: 73
- Joined: Wed Jun 28, 2006 3:27 pm
- Location: NJ
Ok. I will try to explain in a detailed way. But, which version are you on. Is it 7.0 or 7.5? I think you can follow this approach if you are on 7.5. Not sure on 7.0
In your server Job declare the file name as parameter(say #FILENAME#). Now, you will need to use this Job in a Jobsequence. In the Job sequence, you will need to use a Jobactivity to run this Job.Now, in the Job activity stage it is going to ask you all the parameters needed for your server Job and among them one of them is the parameter FILENAME. Now, in the JobAcvitiy stage go to the Job tab where it displays the parameters. Now, for the FILENAME parameter if you click the browse button at the end and then right click within that box, you will find the expression editor from where you can concatenate your filename with a date which can be stripped of the "-" characters you are worried about using more than one ways.
IHTH
In your server Job declare the file name as parameter(say #FILENAME#). Now, you will need to use this Job in a Jobsequence. In the Job sequence, you will need to use a Jobactivity to run this Job.Now, in the Job activity stage it is going to ask you all the parameters needed for your server Job and among them one of them is the parameter FILENAME. Now, in the JobAcvitiy stage go to the Job tab where it displays the parameters. Now, for the FILENAME parameter if you click the browse button at the end and then right click within that box, you will find the expression editor from where you can concatenate your filename with a date which can be stripped of the "-" characters you are worried about using more than one ways.
IHTH
Kris
Where's the "Any" key?-Homer Simpson
Where's the "Any" key?-Homer Simpson
You can also use the after stage subroutine to rename your file. This way you can use the oconv function to get your date in the desired format.
Something like
Arg1 will be the fully qualified name of your file.
Something like
Code: Select all
FileName = Arg1
CurrDate = Oconv(Date(), "DMDY[2,2,4]": @VM : "MCN")
NewFileName = FileName:"_":CurrDate:".txt"
DosCommand = "ren ":FileName NewFileName
Call DSExecute ("DOS",DosCommand,Output,SystemReturnCode)
Ans = SystemReturnCode
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
-
- Participant
- Posts: 73
- Joined: Wed Jun 28, 2006 3:27 pm
- Location: NJ
Ok I tried this to build as an After job subroutine
Now its getting compiled without errors.
But how shall I include in the job ?
I have selected the subroutine as after job subroutine in JOB PROPERTIES. Then in input value I have used file name for eg : "test.txt"
Then in Sequential file stage in the file name I have typed whole pathname/#SUBROUTINENAME#
Is this the way ?
If yes I am not getting required output. I am generating file #SUBROUTINENAME#
Thanks
Now its getting compiled without errors.
But how shall I include in the job ?
I have selected the subroutine as after job subroutine in JOB PROPERTIES. Then in input value I have used file name for eg : "test.txt"
Then in Sequential file stage in the file name I have typed whole pathname/#SUBROUTINENAME#
Is this the way ?
If yes I am not getting required output. I am generating file #SUBROUTINENAME#
Thanks
"Nobody is expert in Everything,
But Everybody is expert in Something."
But Everybody is expert in Something."
No. You cannot pass your filename. The input value takes the value you give for the Arg1 in your routine. As per DSGuru, if you have done everything, then you would need to pass the full path of the file as your input value. However, I believe you can also use parameters in the input value field in the Job Properties.
As per your Job, if you have created the sequential file as pathname/#subroutine# then pass the same full path in the input value in the job properties.
HTH
As per your Job, if you have created the sequential file as pathname/#subroutine# then pass the same full path in the input value in the job properties.
HTH
Kris
Where's the "Any" key?-Homer Simpson
Where's the "Any" key?-Homer Simpson
-
- Participant
- Posts: 73
- Joined: Wed Jun 28, 2006 3:27 pm
- Location: NJ
No I am getting error.
Cannot create file.
See in Job properties I am using
Parameter Value
FILE Path/test.txt
Now I have a built above subroutine under name testsubroutine
So In job properties I am selecting this as after subroutine and in its input value I am using #FILE#
Now In sequential stage in file name i am using
path/#testsubroutine#
Is this correct procedure ? Becoz I am getting error.
Cannot create file.
See in Job properties I am using
Parameter Value
FILE Path/test.txt
Now I have a built above subroutine under name testsubroutine
So In job properties I am selecting this as after subroutine and in its input value I am using #FILE#
Now In sequential stage in file name i am using
path/#testsubroutine#
Is this correct procedure ? Becoz I am getting error.
"Nobody is expert in Everything,
But Everybody is expert in Something."
But Everybody is expert in Something."
If your sequential file path looks like this
#pathname#/#filename# where pathname is the directory and filename is the name of the file you are creating,
then in the input value of the after job sub-routine you will have to give the input value as #pathname#/#filename#.
Now, are you sure that you have the parameters #pathname# and #filename# in the parameters section of your Jobproperties?
Also, are you using different parameters? You mention File Path/test.txt and path/#testsubroutine#. I am kinda getting confused over there.
#pathname#/#filename# where pathname is the directory and filename is the name of the file you are creating,
then in the input value of the after job sub-routine you will have to give the input value as #pathname#/#filename#.
Now, are you sure that you have the parameters #pathname# and #filename# in the parameters section of your Jobproperties?
Also, are you using different parameters? You mention File Path/test.txt and path/#testsubroutine#. I am kinda getting confused over there.
Kris
Where's the "Any" key?-Homer Simpson
Where's the "Any" key?-Homer Simpson
What exactly are you trying to do? The only place you can run an 'After Job Subroutine' is, oddly enough, after the job has completed.
Are you trying to create a file with a date stamp in it? If so you would use your parameterized 'static' filename in the Sequential File stage and then also pass it to the After Job subroutine where it would rename it to include the date after the file is built.
If you need to do something else, be specific.
Are you trying to create a file with a date stamp in it? If so you would use your parameterized 'static' filename in the Sequential File stage and then also pass it to the After Job subroutine where it would rename it to include the date after the file is built.
If you need to do something else, be specific.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 73
- Joined: Wed Jun 28, 2006 3:27 pm
- Location: NJ
Yes I am using the same path in both. There are no different parameters used. What kriss suggested I have tried but getting error.
And yes chulett basically I want to create an output file with timestamp appended like
test_08152006.txt. So my question to you is do I need to first create a file test.txt and then change it to desired name ? Or directly I get the desired file name ?
And yes chulett basically I want to create an output file with timestamp appended like
test_08152006.txt. So my question to you is do I need to first create a file test.txt and then change it to desired name ? Or directly I get the desired file name ?
"Nobody is expert in Everything,
But Everybody is expert in Something."
But Everybody is expert in Something."
You can directly create the file with the date as long as you've got the information to use in the filename when the job starts. Or if one of the existing macros will work for you. Typically, this is passed in as a job parameter and used in the filename.
The path I assume you are following, since you are supposedly using the posted routine, is to create the file in the job without the date and then to rename it after you are done using something like the routine posted. Or a simple script or batch file. Either one is leveraged 'after job'.
Both ways work.
The path I assume you are following, since you are supposedly using the posted routine, is to create the file in the job without the date and then to rename it after you are done using something like the routine posted. Or a simple script or batch file. Either one is leveraged 'after job'.
Both ways work.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 73
- Joined: Wed Jun 28, 2006 3:27 pm
- Location: NJ
Can you please point out where I could be making the silly mistake if I am using the above subroutine and above mentioned details while running the job.
The other option of using Macro I have tried following way in the sequential file stage of output:
test_#DSJobStartDate#.txt
But i have a problem it will append like
test_2006-08-15.txt
and I want test_08152006.txt
The other option of using Macro I have tried following way in the sequential file stage of output:
test_#DSJobStartDate#.txt
But i have a problem it will append like
test_2006-08-15.txt
and I want test_08152006.txt
"Nobody is expert in Everything,
But Everybody is expert in Something."
But Everybody is expert in Something."