Page 1 of 1

Dynamic Output File name

Posted: Mon May 10, 2004 8:50 am
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?

Re: Dynamic Output File name

Posted: Mon May 10, 2004 9:12 am
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

Posted: Mon May 10, 2004 9:18 pm
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.

Posted: Tue May 11, 2004 1:56 am
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

To include a running oracle sequence or DS sequence

Posted: Wed May 19, 2004 4:17 pm
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

Posted: Wed May 19, 2004 10:01 pm
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.

Posted: Wed May 19, 2004 11:22 pm
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.