Passing a Job Parameter for picking up a dynamic 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
Shaina Austin
Participant
Posts: 17
Joined: Wed Jul 07, 2004 7:59 am

Passing a Job Parameter for picking up a dynamic File Name

Post by Shaina Austin »

Hi,

My scenario here is that I have to automate my server job and it should pickup the file name dynamically. The file name comes from the source suffixed with the current date, i.e., xxx20050201.txt and next day it will be xxx20050202.txt

I need help in passing this file name as a parameter so that the job picks up the correct file name. Moreover, at the time when the job runs, the directory where the file resides will have only one file starting with xxx.

I am able to parameterize the file name in a parallel job, but I am unable to do this in the server job.

Any help is greatly appreciated.

Thx.
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post by ketfos »

Hi,
Have Before Job Routine as -
IF the file is on Unix , do

Varx =`ls xxx*` (before job routine)
Then pass this Varx as parameter.

Ketfos
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
If your file is sequential you can use the filter command:
cat <filee path>/xxx*
even saves you the parameter usage ;)

IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

You do the same thing in your server job that you would do in your parallel job. Where you enter the file name use the job parameter enclosed by hash symbols. Eg. #PROJECT_PATH#/#SOURCE_DIR#/#FILE_NAME#
or
#PROJECT_PATH#/#SOURCE_DIR#/xxx#FILE_DATE#.txt
or
#FILE_PATH/#FILE_NAME#

Lots of ways to do it.
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Post by talk2shaanc »

Use this routine, it will give you the file name.

*Function GetFileName(FileName,FilePath)
Deffun DSRMessage(A1, A2, A3) Calling "*DataStage*DSR_MESSAGE"
RoutineName='GetFileName'


Call DSExecute("DOS", 'Dir /b ':FilePath:'\':FileName:'*', Output, SystemReturnCode)

If Trim(Output) = "File Not Found" Then
Message = DSRMessage("DSTAGE_TRX_I_0005", "<L>*** Output from command was: ***<L>", ""):Output
GoTo ErrorExit
End Else
Message = DSRMessage("DSTAGE_TRX_I_0006", "<L>*** No output from command ***", "")
End
If SystemReturnCode = 0 Then
Message = DSRMessage("DSTAGE_TRX_I_0003", "Executed command: ", ""):'Dir ':FilePath:'\':FileName:'*':Message
Call DSLogInfo(Message, RoutineName)
End Else
Message = DSRMessage("DSTAGE_TRX_I_0004", "Error when executing command: ", ""):'Dir ':FilePath:'\':FileName:'*':Message
GoTo ErrorExit
End

* Exit with no error.
ErrorCode = 0
GoTo NormalExit

* Exit with error, logging warning message first.
ErrorExit:
Call DSLogWarn(Message, RoutineName)
ErrorCode = 1
Abort


NormalExit:
Ans=Output
Return(Ans)
------
pass this value as a parameter, to your job.
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Post by talk2shaanc »

sorry forgot to mention this will work for NT server.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

You can link the file to a generic file name and use the generic file name in your jobs.

For e.g., you can do the following in 'Before-Job subroutine'

ln GenericFileName xxx*

and in your job, you can use the file called 'GenericFileName'.

Once your job finishes, you can (optionally as a good practice) remove the link saying

rm GenericFileName

This is assuming that you will have only one file name in that dir with the starting (prefix) of xxx.

Alternatively, try to obtain the date from the Unix run date (date) command and suffix with xxx in the above link as you find suitable.
sankar18
Participant
Posts: 34
Joined: Mon Dec 16, 2002 1:18 am

Post by sankar18 »

To handle the dynamic filename, have the filename as job parameter like filename and date, job parameter enclosed by hash symbols. Eg.

#PATH#/#DIR#/#FILENAME##DATE#.txt

while running the job the give the value for path, dir, filename, date. so that it will pick the correct file.
vigneshra
Participant
Posts: 86
Joined: Wed Jun 09, 2004 6:07 am
Location: Chennai

Post by vigneshra »

Hi
Declare a parameter in the job for holding filename. From the shell script you call the job, just get the name of the file from the specified directory (since the only file in the directory is the required file), and pass it as the job parameter to the job. That solves the problem!
Vignesh.

"A conclusion is simply the place where you got tired of thinking."
suma
Participant
Posts: 32
Joined: Fri Jun 11, 2004 8:18 am

Post by suma »

Hi,,
I understand from your example that the prefix of ur
File Name xxx is constant,
So i can write a routine to get the sysdate Iin wat ever format u need)
and concatenete with the prefix of your fileName and use the value that is returned as FIle Name.

But my problem is,
i am not sure what exactly i should do to use the value that is returned from the routine as the File name?

While browsing the Forum i came to know that we can use this code in the Job COntrol

DEFFUN RoutineName(Arg1, Arg2, Arg3) Calling "DSU.RoutineName"

But again how can i get the value that is returned and use it as my file name.
Is there any way to directly use the returned value as FileName or
it can be done thro parameters only.

Can any one help me to solve this.

Thanks

SumA
Thanks
vskr72
Premium Member
Premium Member
Posts: 128
Joined: Wed Apr 28, 2004 9:36 pm

Re: Passing a Job Parameter for picking up a dynamic File Na

Post by vskr72 »

Shaina - Pls let me know what solution you adopted. I have asimilar requirement but, the OS is unix. appreciate your help.

Kumar
Post Reply