Dynamic Output 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
murur
Participant
Posts: 19
Joined: Wed Apr 14, 2004 7:55 am

Dynamic Output File name

Post by murur »

I have to take an input file INPUT_<MMDDYY99>.EXT and process it
and save the output in OUTPUT_<MMDDYY99>.EXT

How I can implement this .... Any help?
rwierdsm
Premium Member
Premium Member
Posts: 209
Joined: Fri Jan 09, 2004 1:14 pm
Location: Toronto, Canada
Contact:

Re: Dynamic Output File name

Post by rwierdsm »

murur wrote:I have to take an input file INPUT_<MMDDYY99>.EXT and process it
and save the output in OUTPUT_<MMDDYY99>.EXT

How I can implement this .... Any help?
I just had to do the same thing for an output file. See the link below to a thread for some good ideas on what to do on the UNIX side.

I used the following command to rename my output file to have a timestamp:

Code: Select all

mv file file_$(date '+%Y%m%d').txt
viewtopic.php?t=85442&start=0&postdays= ... amic+stamp

Rob Wierdsma
www.bartonbishop.com
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

You've got two ways to go, you can ask the user to enter the date as a job parameter and then use this parameter to create INPUT and OUTPUT file names or you can retrieve the contents of the directory and find the file name using some BASIC code.

In this case you would look in the source directory, retrieve the file name, move the file to a processing directory and start processing it. That way you leave the landing directory free for files that haven't been processed yet. The date can be pulled out of the file name using various BASIC commands.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Here's an after-stage subroutine I baked earlier. It is passed the file pathname via the Input Value field - a job parameter reference can be used there. The purpose of this was to add the date between the base part of the file name and its suffix.

Code: Select all

SUBROUTINE RenameFileWithDate(InputArg, ErrorCode)
$COPYRIGHT "Copyright (c) 2004, Ray Wurlod.  All rights reserved."
$* New file name has the form  filename-YYYY-MM-DD.txt
EQUATE RoutineName To "RenameFileWithDate"

FilePath = InputArg
NewFilePath = Left(FilePath, Len(FilePath) - 4)  ; * remove ".txt"
NewFilePath := "-" : Oconv(@DATE, "D-YMD[4,2,2]") : ".txt"

If System(91)
Then
   * Windows
   Call !GET.PATHNAME(NewFilePath, DirPath, BaseName, Code)
   Command = "RENAME " : FilePath : " " BaseName
   Shell = "DOS"
End
Else
   * UNIX
   Command = "mv " : FilePath : " " : NewFilePath
   Shell = "UNIX"
End
Call DSExecute(Shell, Command, Output, Code)

Call DSLogInfo("Renamed " : FilePath : " to " : NewFilePath, RoutineName)

RETURN
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jreddy
Premium Member
Premium Member
Posts: 202
Joined: Tue Feb 03, 2004 5:09 pm

To include a running oracle sequence or DS sequence

Post by jreddy »

Hi guys,
Did any of you try to generate the output file name dynamically using a sequence. Basically, i want the output file to have the name as
<sequence_number><'STRING'><timestamp>.txt
The 'string' is a constant value, so no problem with that and no problem with timestamp, but generating the running sequence is a problem.
There is no restriction on how i need to generate the sequence.. I could either use DS sequence generator or the oracle sequence

Please share your suggestions with me.
Thanks,
Jyothi
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

You could maintain a sequence within a text file where you read a value in, increment it and write it back again. This is easily managed in a routine through the sequencial file commands. The routine would be called by the sequence job, it passes the name of the file, the routine opens the file and returns to the calling sequence job the next sequence number.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

And, if you do that, you can use UNIX commands to generate a file name that includes the sequence.

Code: Select all

touch myfile_`cat sequencefile`.txt
Yay!
It follows that you can use the same trick with dates and other bits of file names.
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