Function to Get End time and Elapsed Time

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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you're running in an after-job routine, end date/time can be obtained from the system functions Date() and Time(), or TimeDate().
Elapsed time can be obtained by getting the job's start date/time using DSGetJobInfo(DSJ.ME, DSJ.JOBSTARTTIMESTAMP) and subtracting.

Alternately, obtain the Control entries from the log (DSGetLogSummary function, then DSGetLogEntry function). The times you require are recorded in these.


Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Start time for DSGetLogSummary is job start time, end time is any time now in the future. This will give you the entries for the most recent run of the job.

Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
azens
Premium Member
Premium Member
Posts: 24
Joined: Tue Feb 25, 2003 11:59 pm

Post by azens »

Hi,

You can try this function 'DSMakeJobReport'.
It generates a string describing the complete status of a valid attached job.

There are some sample codes I wrote in a routine to capture the start time, end time, elapsed time, status and status description for jobs.

**
JobHandle = DSAttachJob(JobName, DSJ.ERRNONE)
Content = DSMakeJobReport(JobHandle, 0, 'LF')

JobStart = Field(Field(Content, Char(10), 5), '=', 2)
JobEnd = Field(Field(Content, Char(10), 6), '=', 2)
JobElapsed = Field(Field(Content, Char(10), 7), '=', 2)
JobStatus = Field(Field(Field(Content, Char(10), 8), '=', 2), ' ', 1)
JobDesc = Field(Field(Field(Content, Char(10), 8), '(', 2), ')', 1)

**

Try it, it works.

regards,
Azens


Azens Chang
MetaEdge Corp.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

DSMakeJobReport was introduced in DataStage 5.0. If you're running an earlier release this is not available to you.

That said, it is not a bad suggestion! [8D]

Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
datastagedummy
Participant
Posts: 56
Joined: Thu Feb 13, 2003 6:08 pm
Location: USA

Post by datastagedummy »

Here is the piece of code that I use hope it helps

vJobBatchName = DSGetJobInfo(DSJ.ME, DSJ.JOBNAME)
vJobName = rpt$[(Index(rpt$,"STATUS REPORT FOR JOB:",1)+22),Index(rpt
$,"Generated:",1)-(Index(rpt$,"STATUS REPORT FOR JOB:",1)+23)]

vTimeStamp = rpt$[Index(rpt$,"Generated:",1)+11, 19]
vStartTime = rpt$[Index(rpt$,"Job start time=",1)+15, 19]
vEndTime = rpt$[Index(rpt$,"Job end time=",1)+13, 19]
vJobStat = rpt$[Index(rpt$,"Job status=",1)+11, 2]
datastagedummy
Participant
Posts: 56
Joined: Thu Feb 13, 2003 6:08 pm
Location: USA

Post by datastagedummy »

I am sorry I forgot the first step

rpt$ = Iconv(DSMakeJobReport(hJob,0,"LF"),"MCP")

where hJob is the job handle obtained by DSAttachJob() function
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

There's no direct CLI equivalent for DSMakeJobReport. The -jobinfo option comes closest, but will not provide all the information you seek. If you can identify the job number, then you could inspect the date/time modified of the job's status table (RT_STATUSxx) or log table (RT_LOGxx), which will be very close to the job finish time.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Not easily.
The metadata for these tables refers only to the key column (@ID), so that accessing any other column, collection or other structure within the table (remember that it's not first normal form) requires certain knowledge - and understanding - about the record layouts (which varies for different record types). This information is not in the public domain.
Similarly access from the operating system command prompt can not be achieved directly (they are database tables, after all). However, they are implemented as operating system objects, so you should be able to use something like attrib to determine the date/time modified (which was my suggestion).
Decoding job name to job number is done in the DS_JOBS table. Again this can only be indirectly be accessed from the operating system.

Also check out the options in dsjob for finding the most recent event in the job log, the timestamp in which should be the job finish time.
Post Reply