Append date with file

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

urshit_1983
Participant
Posts: 73
Joined: Wed Jun 28, 2006 3:27 pm
Location: NJ

Append date with file

Post by urshit_1983 »

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
"Nobody is expert in Everything,
But Everybody is expert in Something."
meena
Participant
Posts: 430
Joined: Tue Sep 13, 2005 12:17 pm

Post by meena »

Hi urshit_1983,
You can append the date to the file through a routine. You can do a search in the forum you will find more information too...

Thank you
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

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.
Kris

Where's the "Any" key?-Homer Simpson
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

If you mean rename, use a Routine call to the OS and the "ren" command.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
urshit_1983
Participant
Posts: 73
Joined: Wed Jun 28, 2006 3:27 pm
Location: NJ

Post by urshit_1983 »

But what if I use DSJobStartDate in seq file name like -

test_#DSJobStartDate#.txt

But i have a problem it will append like

test_2006-08-01.txt

and I want test_08012006.txt

And I didnt get your sequencer concept ?
"Nobody is expert in Everything,
But Everybody is expert in Something."
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

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
Kris

Where's the "Any" key?-Homer Simpson
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

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

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
Arg1 will be the fully qualified name of your file.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
urshit_1983
Participant
Posts: 73
Joined: Wed Jun 28, 2006 3:27 pm
Location: NJ

Post by urshit_1983 »

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
"Nobody is expert in Everything,
But Everybody is expert in Something."
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

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
Kris

Where's the "Any" key?-Homer Simpson
urshit_1983
Participant
Posts: 73
Joined: Wed Jun 28, 2006 3:27 pm
Location: NJ

Post by urshit_1983 »

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.
"Nobody is expert in Everything,
But Everybody is expert in Something."
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

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.
Kris

Where's the "Any" key?-Homer Simpson
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:? 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
urshit_1983
Participant
Posts: 73
Joined: Wed Jun 28, 2006 3:27 pm
Location: NJ

Post by urshit_1983 »

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 ?
"Nobody is expert in Everything,
But Everybody is expert in Something."
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
urshit_1983
Participant
Posts: 73
Joined: Wed Jun 28, 2006 3:27 pm
Location: NJ

Post by urshit_1983 »

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
"Nobody is expert in Everything,
But Everybody is expert in Something."
Post Reply