Page 2 of 2

Posted: Mon Aug 28, 2006 6:16 am
by ray.wurlod
You should be able to adapt the following code to your requirements. It reports the name of the job itself if it has no controller.

Code: Select all

FUNCTION UltimateController(JobName)
$IFNDEF JOBCONTROL.H
$INCLUDE DSINCLUDE JOBCONTROL.H
$ENDIF

      Controller = ""
      TempJobName = JobName
      PrevController = JobName
      Loop
         hJob = DSAttachJob(TempJobName, DSJ.ERRNONE)
         Controller = DSGetJobInfo(hJob, DSJ.JOBCONTROLLER)
      While Len(Controller) > 0
         If Controller Matches "'-'1N0N"
         Then
            Ans = @NULL
            Call DSTransformError("Failed to attach job " : Quote(TempJobName),"UltimateParent")
            Exit
         End
         Else
            Call DSLogInfo(Quote(Controller), "UltimateParent")
            PrevController = Controller
            ErrCode = DSDetachJob(hJob)
            TempJobName = Controller
         End
      Repeat

      Ans = PrevController

RETURN(Ans)