Page 1 of 1

Appending timestamp to filename

Posted: Tue May 09, 2017 8:55 am
by swathi.raoetr
Building some simple enough extracts, but need to append filename. I have a sequence job, in which I have a user variable activity. I have used DSJObStartTimestamp. Then used this on the parameter at Job Activity calling the parallel job. No compilation or validation errors. But the job gets aborted on run time. Any suggestions? I want to avoid post unix scripting, as I think DataStage should be able to handle this.

Posted: Tue May 09, 2017 8:58 am
by FranklinE
You didn't provide any messages from Director, so this is a guess: is the file being written to a Unix server or a Windows server? If Windows, your timestamp format might violate Windows file name restrictions.

Posted: Tue May 09, 2017 9:00 am
by UCDI
you can just do this in the user variable stage..

'filename':CurrentTimestampMS()
or
variable:CurrentTimestampMS()

if the format is not acceptable for your filesystem, you can to a replacement of the offending characters ( : is probably the issue, replace that with - or something), or run the timestamp with a formatting string

Posted: Tue May 09, 2017 9:17 am
by swathi.raoetr
FranklinE:

Writing to a hdfs@unix with a file connector.

Posted: Tue May 09, 2017 9:19 am
by swathi.raoetr
UCDI:

For some reason, when I use 'filename':CurrentTimestampMS() in user variable activity stage it is giving the error variable CurrentTimestampMS() not defined; PS: We are not admins for this environment.

Posted: Tue May 09, 2017 9:44 am
by chulett
You may not need to pass in the timestamp, the DSJobStarttime macro should be able to be used directly in the parallel job as part of the filename in the connector stage. Unless you need to reformat it, as noted, then that would need to happen in the sequence job before passing it to the job.

Posted: Tue May 09, 2017 11:13 am
by swathi.raoetr
Tried few options... only way the timestamp's not throwing an error, is by calling the system variable and not the macro. @Date... but this is giving converted 5 digit integer, rather than actual timestamp. Using ereplace.... need to sort the syntax for replacing the special characters.

Posted: Tue May 09, 2017 12:26 pm
by koti9
You may simply call unix shell command in sequence `date +%Y%m%d%H%M%S` and pass it as parameter the next job activity

Posted: Tue May 09, 2017 12:41 pm
by swathi.raoetr
Wanted to avoid shell if possible thru DS... this worked at runtime
ereplace(ereplace(ereplace(DateCurrentGMTTime(-3),':',''),'.',''),'-','')

Posted: Tue May 09, 2017 1:14 pm
by chulett
So... resolved?

Posted: Tue May 09, 2017 1:15 pm
by swathi.raoetr
Yes, Thanks for the inputs given :o