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

chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I know the issue you've got with the macro, we've discussed it quite a bit in recent days so knew the dashes would be an issue.

It's hard for me to know your silly mistake when I can't see your job. What you should be able to do to make it work is have a job parameter with the full path to the file to create - the one without the date. It looks like you've called that FILE, so both the Sequential File stage and the After Job subroutine should use #FILE#. The routine will take the file and rename it with the current date formatted properly I assume. None of this silly #testsubroutine# stuff. :wink:

The other trick here is the filename cannot include the extension for the rename to work correctly. If you are comfortable doing this, drop it from the parameter value and hard-code the ".txt" extension in the Sequential File stage, much like it is hard-coded in the posted routine.

I believe you'll need to modify the routine to pull the filename from the path to it. From what I recall, the DOS rename command wants the full path to the original file, but only the new filename on the other side. For example:

Code: Select all

ren /a/b/c/test.txt test_08152006.txt
Check the help for the command to confirm.
-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 »

Thank you so much. Hope i should be able to get it now.

Thank you everybody for your time.
"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 »

chulett wrote:
I believe you'll need to modify the routine to pull the filename from the path to it. From what I recall, the DOS rename command wants the full path to the original file, but only the new filename on the other side.
And thats exactly what the routine from DSGuru was expecting as Arg1. :wink:
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 »

Ok I have tried but its creating the file with name :

test.txt

No renaming is done and no date is appended to file name.

Is the subroutine given by DSGuru good. Can someone check it please ?


Thnx
"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 »

The routine looks good to me. Have you tried it testing seperately from Manager? What happens when you do that? I would suggest you test it from Manager and make sure that the routine is working as per your requirement(else make some changes) and then try using it in the after job subroutine.
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 »

Yes kris I have tried in Manager but I can only compile and not Test. Dont know why... :?:

May be becoz of the RETURN ??
Because in last line of subroutine posted its Ans=.......
And in bottom tab of routine dialog box its just RETURN.

So may be its not returning the value properly....
"Nobody is expert in Everything,
But Everybody is expert in Something."
prabu
Participant
Posts: 146
Joined: Fri Oct 22, 2004 9:12 am

Post by prabu »

please try the following code. i believe ren is not a valid DOS command , but mv works. All the best!!

Code: Select all

* courtesy DSGuru
* The intention of this site it to give you a fishing rod, worm 
* and fishing boat, somtimes
* it cannot cook the fish remotely  :lol:  :lol: 
FileName = Arg1
CurrDate = Oconv(Date(), "DMDY[2,2,4]": @VM : "MCN")
NewFileName = FileName:"_":CurrDate:".txt" 
DosCommand = "mv ":FileName NewFileName
Call DSExecute ("DOS",DosCommand,Output,SystemReturnCode) 

Ans = SystemReturnCode
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

'ren' is short for rename and is a perfectly valid DOS command, it's 'mv' that isn't. 'mv' is a UNIX command and will work for you only if you have something like the MKS Toolkit installed.

The routine is not quite right, as I noted in my post. It needs to be tweaked to support the syntax as required by the rename command.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

I have made a small change to the routine. I have included the filepath as the parameter where filepath is the dir the file resides. Now, try testing this routine.

Code: Select all

FileName = Arg1 
FilePath =Arg2
CurrDate = Oconv(Date(), "DMDY[2,2,4]": @VM : "MCN") 
NewFileName = FileName:"_":CurrDate:".txt" 
DosCommand = "ren ":FilePath:'\':FileName NewFileName 
Call DSExecute ("DOS",DosCommand,Output,SystemReturnCode) 

Ans = SystemReturnCode
FileName = Name of the file.
FilePath = Path of the file.

And what do you mean by saying that you can only compile and not test? You are not able to test means the routine has not compiled successfully. If you were able to compile the routine without any errors and warnings, then you should be able to test it.
urshit_1983 wrote:Because in last line of subroutine posted its Ans=.......
The last line says Ans = SystemReturnCode.
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 »

Ahaaa. I got my BIGGEST MISTAKE. I didnt notice by mistake, I have posted OS-Windows in my question. But its Unix. Moreover stupid enough that I am using DOS command in the subroutine.

Extremely Sorry guys. So what modifications needed now ??
"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 »

Code: Select all

FileName = Arg1 
FilePath =Arg2 
CurrDate = Oconv(Date(), "DMDY[2,2,4]": @VM : "MCN") 
NewFileName = FileName:"_":CurrDate:".txt" 
UnixCommand = "mv ":FilePath:'/':FileName NewFileName 
Call DSExecute ("UNIX",UnixCommand,Output,SystemReturnCode) 

Ans = SystemReturnCode
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 »

When I am compiling it say : Compiled with no errors
But then the Test button does not get bold. So I cannot click and test it.

Moreover I tried to build a transform routine which worked fine with this code :

FileName = Arg1
FilePath =Arg2
CurrDate = Oconv(Date(), "DMDY[2,2,4]": @VM : "MCN")
NewFileName = FileName:"_":CurrDate:".txt"
Ans = NewFileName
"Nobody is expert in Everything,
But Everybody is expert in Something."
urshit_1983
Participant
Posts: 73
Joined: Wed Jun 28, 2006 3:27 pm
Location: NJ

Post by urshit_1983 »

When I am compiling it say : Compiled with no errors
But then the Test button does not get bold. So I cannot click and test it.

Moreover I tried to build a transform routine which worked fine with this code :

FileName = Arg1
FilePath =Arg2
CurrDate = Oconv(Date(), "DMDY[2,2,4]": @VM : "MCN")
NewFileName = FileName:"_":CurrDate:".txt"
Ans = NewFileName
"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 »

Two things you could do:

1. Create the routine with the code provided earlier as a Before/After subroutine and execute it in your Job and see if its working.

2. Create the routine with the code provided earlier as a Transform Function and test it in the Manager and then use it as Before/After Routine.

Note: Create the Routine in the Before/After Directory in order for it to appear in the Before/After Subroutine in Job Properties window.

I don't think the code you provided solves your purpose as it is just creating a file with a new name. I don't think it's copying the contents of the old file into the new file.
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 »

Wow, this topic is still alive. And after all this time you tell us its unix. Well, it happens :)
If its unix then you dont even need a routine. Just append the date to the file by running afterjob subroutine 'Execsh'

Code: Select all

mv yourfile.txt yourfile_`date +"%Y%m%d"`.txt
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply