Monday, March 12, 2012

Job distinct / unique / total runs

If a job goes in ABEND and it is not fixed in the same TWS day it will be added to TWS historical database multiple times (as many times as UPDATESTATS jobs run) so the job runs number isn't accurate when we use rep7 to report them, below examples are ran using ORACLE DB.


The below SQL query will remove the duplicate items added by UPDATESTATS for unattended ABEND jobs:
       
alter session set current_schema=maestro_DB_user;

SELECT count(*) FROM (SELECT DISTINCT AJS_NAME, AJB_NAME, JHR_START_TIME, JHR_RUN_DATE, 
JHR_TOTAL_ELAPSED_TIME,JHR_STATUS, WKC_NAME FROM JHR_JOB_HISTORY_RUNS
WHERE jhr_run_date>=trunc(sysdate-12) AND jhr_run_date <trunc(sysdate+1)) 
WHERE (AJB_NAME like 'MAKEPLAN')


Also if you want to see only the unique jobs that ran on a specific workstation:

       
alter session set current_schema=maestro_DB_user;

SELECT count(*) FROM (SELECT UNIQUE AJB_NAME FROM (SELECT DISTINCT AJS_NAME, AJB_NAME, JHR_START_TIME,
JHR_RUN_DATE, JHR_TOTAL_ELAPSED_TIME , JHR_STATUS, WKC_NAME  FROM JHR_JOB_HISTORY_RUNS
WHERE jhr_run_date>=trunc(sysdate-12) AND jhr_run_date <trunc(sysdate+1)) 
WHERE (WKC_NAME like 'TWSMASTER'))



And a nice report containing all job runs, all success runs, all ABEND / CANCEL ones, unique jobs success and unique jobs failed:

       
alter session set current_schema=maestro_DB_user;

SELECT
Count (CASE WHEN JHR_STATUS = 'S' or JHR_STATUS = 'A' 
or JHR_STATUS = 'C' THEN '1' ELSE NULL END) All_Job_Runs,
Count (CASE WHEN JHR_STATUS = 'S' THEN '1' ELSE NULL END) All_Runs_Sucessful,
Count (CASE WHEN JHR_STATUS = 'A' or JHR_STATUS = 'C' THEN '1' ELSE NULL END) All_Runs_Failed,
Count (DISTINCT CASE WHEN JHR_STATUS = 'S' THEN AJB_NAME ELSE NULL END) Unique_Jobs_Successful,
Count (DISTINCT CASE WHEN JHR_STATUS = 'A' 
or JHR_STATUS = 'C' THEN AJB_NAME ELSE NULL END) Unique_Jobs_Failed
FROM (select distinct AJS_NAME, AJB_NAME, JHR_START_TIME, JHR_RUN_DATE, JHR_TOTAL_ELAPSED_TIME,
JHR_STATUS, WKC_NAME from JHR_JOB_HISTORY_RUNS
WHERE jhr_run_date>=trunc(sysdate-12) AND jhr_run_date <trunc(sysdate+1));



Hint: Modify sysdate-+XX to adjust the number of days on which the reports are ran, also you can use dates as: 

       
jhr_run_date>=TO_DATE('10/03/2012','dd/mm/yyyy') AND jhr_run_date <TO_DATE('12/03/2010','dd/mm/yyyy')


8 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi Radu,

    all success runs, all ABEND / CANCEL ones, unique jobs success and unique jobs failed: sql query is not working....Im using 8.5.1....Also do you have sql query for Carry forward report also...

    ReplyDelete
    Replies
    1. Hi Vinay,

      What error do you get?
      I've test it and it works on 8.3 and 8.6.

      Delete
    2. im running below query:
      SELECT
      Count (CASE WHEN JHR_STATUS = 'S' or JHR_STATUS = 'A'
      or JHR_STATUS = 'C' THEN '1' ELSE NULL END) All_Job_Runs,
      Count (CASE WHEN JHR_STATUS = 'S' THEN '1' ELSE NULL END) All_Runs_Sucessful,
      Count (CASE WHEN JHR_STATUS = 'A' or JHR_STATUS = 'C' THEN '1' ELSE NULL END) All_Runs_Failed,
      Count (DISTINCT CASE WHEN JHR_STATUS = 'S' THEN AJB_NAME ELSE NULL END) Unique_Jobs_Successful,
      Count (DISTINCT CASE WHEN JHR_STATUS = 'A'
      or JHR_STATUS = 'C' THEN AJB_NAME ELSE NULL END) Unique_Jobs_Failed
      FROM (select distinct AJS_NAME, AJB_NAME, JHR_START_TIME, JHR_RUN_DATE, JHR_TOTAL_ELAPSED_TIME,
      JHR_STATUS, WKC_NAME from JHR_JOB_HISTORY_RUNS
      WHERE jhr_run_date>=trunc(02/02/2015-12) AND jhr_run_date <trunc(02/02/2015+1));

      and error is:
      AWSUI0331E An internal error has occurred.. The SQL query could not be validated. The database internal message is:
      ORA-00911: invalid character

      Delete
    3. Hi Vinay,

      You are using the query date format wrong:
      trunc(02/02/2015-12) AND trunc(02/02/2015+1));

      It should be:
      trunc(sysdate-12) AND trunc(sysdate+1)); --sysdate is the OS date

      or:
      TO_DATE('10/02/2015','dd/mm/yyyy') AND TO_DATE('04/03/2015','dd/mm/yyyy'));

      Delete
    4. Its working now...thanks for your help

      Delete
  3. Hello Radu,

    Learnt so many things from your blogs. Are you going to post another blog? How about managing WAS for TWS?

    ReplyDelete
    Replies
    1. Hi Vinay,

      Yes, i plan to post more "hints" and "how to" but i am very busy at the moment.

      Also any suggestion on which you need more clarification or you face any issues is welcome :-).

      Delete