need to include sysdate into the file name

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

Post Reply
Jagan617
Participant
Posts: 42
Joined: Thu Jun 05, 2008 7:37 pm

need to include sysdate into the file name

Post by Jagan617 »



Actually i am ftping the file from the upstreams to ETL server, in the ETL server i need to keep the filename as TCyyyymmdd.txt where YYYYMMDD is the current date.

Can anyone assist me in this.
mail2hfz
Premium Member
Premium Member
Posts: 92
Joined: Thu Nov 16, 2006 8:51 am

Re: need to include sysdate into the file name

Post by mail2hfz »

Jagan617 wrote:

Actually i am ftping the file from the upstreams to ETL server, in the ETL server i need to keep the filename as TCyyyymmdd.txt where YYYYMMDD is the current date.

Can anyone assist me in this.

After FTP,you can rename as

mv filename filename_`date '%Y%m%d`
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

That is trickier to do on a Windows operating system. You could use a routine from a Routine activity. The following code is generic - it will work on either UNIX or Windows. Error handling has been omitted for clarity.

Code: Select all

FUNCTION AddDateToFileName(FileName)
* Add yyyymmdd between base name and suffix.
* FileName is the pathname of the file to be changed.
* Generates and executes appropriate rename command.

   Ans = @NULL
 
   Elements = DCount(FileName, ".")
   BaseName = Field(FileName, ".", 1, Elements - 1)
   Suffix = Field(FileName, ".", Elements, 1)

   Call !GET.PATHNAME(FileName, DirPath, EntryName, StatusCode)

   NewFileName = EntryName : Oconv(@DATE,"DYMD[4,2,2]":@VM:"MCN") : "." : Suffix

   If System(91)
   Then
      Shell = "DOS"
      Command = "REN " : FileName : " " : NewFileName
   End
   Else
      Shell = "UNIX"
      Command = "mv " : FileName : " " : NewFileName
   End

   Call DSExecute(Shell, Command, Output, ExitStatus)
   Ans = ExitStatus


RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply