How to Handle Changing Database 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
olgc
Participant
Posts: 145
Joined: Tue Nov 18, 2003 9:00 am

How to Handle Changing Database Name?

Post by olgc »

Hi There,

If the database naming keeps changing every day when it's read, like the db name DB_20041020, how can you handle it? For example, when DB:'_':DATE.TAG(DATE())[1,4]:DATE.TAG(DATE())[5,2]:DATE.TAG(DATE())[7,2] is used as Database in a DB stage, it doesn't convert to DB_20041020, it keeps "DB:'_':DATE.TAG(DATE())[1,4]:DATE.TAG(DATE())[5,2]:DATE.TAG(DATE())[7,2]" as the database name. So we have the follwing error:

DailyActivity..SourceServer: Attempt to access specified database failed.
SQL statement: use DB:'_':DATE.TAG(DATE())[1,4]:DATE.TAG(DATE())[5,2]:DATE.TAG(DATE())[7,2]
DailyActivity..SourceServer.DSLink1: DSP.Open GCI $DSP.Open error -2.

Any one has an idea how to hanlde the changing database name in a DB stage?

Thanks every body there,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You would need to make it a Job Parameter and then reference that parameter, bounded by pound signs (#), in the DB stage.

Do something like you are doing in an outer job control 'wrapper' or script to set the parameter value accordingly.
-craig

"You can never have too many knives" -- Logan Nine Fingers
olgc
Participant
Posts: 145
Joined: Tue Nov 18, 2003 9:00 am

Post by olgc »

Hi Craig,

Thanks for your quick resopnse. I try to wrap it in a control job, but still do not know how it is handled. The code is as the following:

L$2$START:
*** Activity "JobActivity_1": Initialize job
jb$2 = "testit"
h$2 = DSAttachJob(jb$2, DSJ.ERRNONE)
If (Not(h$2)) Then
msg$ = DSMakeMsg("DSTAGE_JSG_M_0001\Error calling DSAttachJob(%1)<L>%2", jb$2:@FM:DSGetLastErrorMsg())
msg$id = "@JobActivity_1"; GoTo L$ERROR
End
p$2$1 = (ddtt)
err$code = DSSetParam(h$2, "dt", p$2$1)
If (err$code <> DSJE.NOERROR) Then
msg$ = DSMakeMsg("DSTAGE_JSG_M_0002\Error calling DSSetParam(%1), code=%2[E]", "dt":@FM:err$code)
msg$id = "@JobActivity_1"; GoTo L$ERROR
End
err$code = DSRunJob(h$2, DSJ.RUNNORMAL)
If (err$code <> DSJE.NOERROR) Then
msg$ = DSMakeMsg("DSTAGE_JSG_M_0003\Error calling DSRunJob(%1), code=%2[E]", jb$2:@FM:err$code)
msg$id = "@JobActivity_1"; GoTo L$ERROR
End
handle$list<-1> = h$2
id$list<-1> = "2"
Return

Could you show me how p$2$1 is set to fit the requirement? Suppose the db name is DB_YYYYMMDD.

Thanks,
olgc
Participant
Posts: 145
Joined: Tue Nov 18, 2003 9:00 am

Post by olgc »

If p$2$1 is set as the following:

p$2$1 = 'DB':'_':DATE.TAG(DATE())[1,4]:DATE.TAG(DATE())[5,2]:DATE.TAG(DATE())[7,2]

When the job is compiled, the error below is occurred:

"Error compiling Job Control Subroutine conn. "

conn is the control job name.

Any idea?

Thanks,
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

This looks like Sequence job code that has been copied and pasted into a batch control job. The problem with this code is that it's not really maintainable as it's generated when the sequence job is compiled and is not meant to be modified by users.

I'd try turning this back into a sequence job and see if you can add the required functionality via a combination of a sequence job and called job control routines.
alokkum
Participant
Posts: 8
Joined: Tue Aug 03, 2004 7:16 pm

Post by alokkum »

You can make this happen through the sequencer job control. Create a parameter file which contains the date to be tagged to the table/database names. Have this parameter in the job as well as in the sequencer.
Do proper parameter mappings in the sequencer for any such job which has a changing table/database name.
After compiling the sequencer, take the compiled code from the job control and create another batch job where you paste this code.
Make necessary additions to read these parameter variables from the parameter file.
Hope this works
Thanks
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

I think this is not a good idea. Sequencer code is very very ugly. To create this manual process to cut and paste this code into a batch job is a waste of time. I posted a routine the can be called from a routine activity which will set any job parameter in the current sequence. This is super clean. All you have to do is modify this routine to lookup any parameter value you like and then run the job that needs this value after this routine. It is exactly what is missing from a sequence. NO MORE BATCH JOBS EVER. I can write BASIC code better than most of you and this is by far the cleanest way to lookup parameters and feed them into a sequence.

Do a search for KgdSetLastKeyParam. If you need help modifying it then let me know. I have another version which will read a whole list of parameters from a sequential file and set any or all of them. Peter Lai wrote it. He has used Universe since 1986 and DataStage since version 1.0. He is the best.
Mamu Kim
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Ooh, that sounds like a challenge! I come from UniVerse's parent (Prime INFORMATION), beginning in 1983, via UniVerse, and DataStage 1.0 also. :lol:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Oh, well... I've worked with Prime systems in the distant past, and DataStage since 3.1. Close but no cigar. :cry:
-craig

"You can never have too many knives" -- Logan Nine Fingers
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Ray

I said most of the posters not all. I only started using Universe in 1986 and Pick before that. Still I think that is long enough to recognize a better way to do something.
Mamu Kim
Post Reply