Looping Job based on input from hashfile lookup

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
marc_brown98
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 14, 2004 11:33 am

Looping Job based on input from hashfile lookup

Post by marc_brown98 »

All,
I have a job that needs to go to muptiple servers and run the exact same job(s) at each server. I'm struggling on whether to just code a one looping job solution OR use sequencers to call the same job(s) multiple times. There are about 85 locations that need to be executed at.

Right now, I have a hash file that is generated that gives me a list of location ID's and IP addy's/names that get passed through in as params to the job(s). The control mechanisms seem to be a little challenging at this point.
I'd prefer the elegant 1 job solution as it would produce less maintenance, but have somewhat limited experience coding this setup in DS.
marc_brown98
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 14, 2004 11:33 am

Post by marc_brown98 »

some more input, this is the single job code I have now, but it's not performing as expected.. It needs to break out after each center and move to the next. I've probably been staring at this code too long and its something smal that I'm missing. Thanks for any input:

Code: Select all

DefFun DSU.HashLookup (A, B, C) Calling "DSU.HashLookup"
DefFun DSU.CheckRunStatus (A, B, C) Calling "DSU.CheckRunStatus"

CenNo=""
IPAddr=""
CenName=""
CenStat=""
HashKey=""
AccessTp=""
ProcessCenter=""
StatusReturned = ""

HashKey = 1
CenNo = DSU.HashLookup(ConfigTable, HashKey, 1)
IPAddr = DSU.HashLookup(ConfigTable, HashKey, 2)


*Call DSLogInfo("---------- Processing Run Type of: " : TrimB(RunType) : " ----------", "JobControl")
Loop While  Left(IPAddr,2) <> "**"
   ProcessCenter = "No"
      * loop while the number of attempts for the center is less than the    maximum (or retry) attempts specified and
      * the job has not ended with a status of successful or warning (a warning means a data quality problem exists that needs fixing).
      * Loop While Attempt < RetryAttempts and StatusReturned <> 0  and StatusReturned <> 1
         Call DSLogInfo (">>>>>>>>>> CenNo:" : CenNo : " Seq: " : SeqNo  : "<<<<<<<<<<", "JobControl")
         hJob1 = DSAttachJob("VPLHExtractGroup1001", DSJ.ERRFATAL)
         ErrCode = DSSetParam(hJob1, "CenNo", CenNo)
         ErrCode = DSSetParam(hJob1, "IPAddr", IPAddr)
         ErrCode = DSSetParam(hJob1, "$SQLEnviron", $SQLEnviron)
         ErrCode = DSSetParam(hJob1, "$SQLUser", $SQLUser)
         ErrCode = DSSetParam(hJob1, "$SQLPassword", $SQLPassword)
         ErrCode = DSSetParam(hJob1, "$DSSeqEnviron", $DSSeqEnviron)
         ErrCode = DSRunJob(hJob1, DSJ.RUNNORMAL)
         hJob1ST = DSGetJobInfo(hJob1, DSJ.JOBSTARTTIMESTAMP)
         hJob1JN = DSGetJobInfo(hJob1, DSJ.JOBNAME)
         ErrCode = DSWaitForJob(hJob1)
         Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
         StatusReturned = DSU.CheckRunStatus (Status, hJob1ST, hJob1JN)
         If StatusReturned < 0 or StatusReturned > 2 Then
            Call DSLogInfo ("JOB " : hJob1JN : " FAILED with unknown status!", "JobControl")
            If BestJobRunStatus <> "Failed" And BestJobRunStatus <> "Warning" Then
               BestJobRunStatus = "UNKNOWN"
            End
            hJob1 = DSAttachJob("VPLHExtractGroup1001", DSJ.ERRFATAL)
            ErrCode = DSRunJob(hJob1, DSJ.RUNRESET)
            ErrCode = DSWaitForJob(hJob1)
         End
         If StatusReturned = 2 Then
            Call DSLogInfo ("JOB " : hJob1JN : " FAILED!", "JobControl")
            If BestJobRunStatus <> "Warning" Then
               BestJobRunStatus = "FAILED"
            End
            hJob1 = DSAttachJob("VPLHExtractGroup1001", DSJ.ERRFATAL)
            ErrCode = DSRunJob(hJob1, DSJ.RUNRESET)
            ErrCode = DSWaitForJob(hJob1)
         End
         If StatusReturned = 1 Then
            Call DSLogInfo ("JOB " : hJob1JN : " DID NOT RUN PROPERLY!", "JobControl")
            BestJobRunStatus = "WARNING"
         End
         If StatusReturned = 0 Then
            Call DSLogInfo ("JOB " : hJob1JN : " ran SUCCESSFULLY!", "JobControl")
            BestJobRunStatus = "SUCCESS"
         End
   Attempt = Attempt + 1
   HashKey = HashKey + 1
   CenNo = DSU.HashLookup(ConfigTable, HashKey, 1)
   IPAddr = DSU.HashLookup(ConfigTable, HashKey, 2)
Repeat
Last edited by marc_brown98 on Thu Jun 18, 2009 10:21 am, edited 1 time in total.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Go back and edit your second post, wrapping the code in

Code: Select all

 tags so it's a wee bit more readable, please. That will preserve your indenting.
-craig

"You can never have too many knives" -- Logan Nine Fingers
marc_brown98
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 14, 2004 11:33 am

Post by marc_brown98 »

my apologies. Updated now.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

OpenPath HashedFilePathname To FHashedFile
Then
   Select fHashedFile To 9
   Loop While ReadNext Key From 9
      Read rHashedFile From fHashedFile, Key
      Then
         CenNo = rHashedFile<1>
         IPaddr = rHashedFile<2>
         ...
         * Calls to DSAttachJob, DSSetParam, etc. here
         ...
      End
   Repeat
End
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
marc_brown98
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 14, 2004 11:33 am

Post by marc_brown98 »

Ray,
My premium membership is expired, so please bear wtih me.
Post Reply