Below script will help to extract all job chain parameter details .

import com.redwood.scheduler.api.model.*;
import java.util.*;

{
   String P_PARAMETERS = “SAP_SYSTEMS,CLIENT,ABAP_PROGRAM_NAME,ABAP_VARIANT_NAME,JOBNAME,NAME,EXT_COMMAND_NAME,EXT_COMMAND_PARAMETERS,EXT_PROGRAM_NAME,EXT_PROGRAM_PARAMETERS”;
   chains = new ArrayList();

   String query = “select jc.* from JobChain jc,JobDefinition jd”
                + ” where jc.JobDefinition = jd.UniqueId”
                + ” and jd.UniqueId = jd.MasterJobDefinition”
                + ” and jd.UniqueId not in (select distinct JobChainCall.JobDefinition from JobChainCall)”;

   for (Iterator it = jcsSession.executeObjectQuery(query, null); it.hasNext();)
   {
     JobChain jc = (JobChain)it.next();
     JobDefinition jd = jc.getJobDefinition();
     listChain(P_PARAMETERS, “”, jd);
  }
}

List chains;
Partition  partition;

  public void listChain(String P_PARAMETERS, String ident, JobDefinition jd)
  {
     jcsOut.print(ident + ” ” + jd.getPartition().getName() + “.” + jd.getName());
     String paramList = null;
     String[] paramArray = P_PARAMETERS.split(“,”);
     String paramValue = “”;
     for (int i = 0; i < paramArray.length; i++)
     {
       if (jd.getJobDefinitionParameterByName(paramArray[i]) != null)
       {
         if (paramList == null)
         {
           paramList = “”;
         }
         paramValue = jd.getJobDefinitionParameterByName(paramArray[i]).getDefaultExpression();
         if (paramValue == null)
         {
            paramValue = “”;
         }
         paramList = paramList + “(” + paramArray[i] + “=” + paramValue + “) “;
       }
     }
     if (paramList != null)
     {
       jcsOut.print(” ” + paramList);
     }
     jcsOut.println(“”);
     showEvents(ident, jd);
     showChain(P_PARAMETERS, ident, jd);
     jcsOut.println(“”);
     jcsOut.println(“”);
     jcsOut.println(“”);
  } 

  public void showEvents(String ident, JobDefinition jd)
  {
    boolean hasEvents = false;
    int raiseAantal = 0;
    int waitAantal = 0;
    // wait events
    for (Iterator it = jd.getJobDefinitionWaitEvents(); it.hasNext();)
    {
      JobDefinitionWaitEvent re = (JobDefinitionWaitEvent)it.next();
      jcsOut.println(ident + ” <== ” + re.getEventDefinition().getName());
      hasEvents = true;
      waitAantal++;
    }
    // raise events
    for (Iterator it = jd.getJobDefinitionRaiseEvents(); it.hasNext();)
    {
      JobDefinitionRaiseEvent re = (JobDefinitionRaiseEvent)it.next();
      jcsOut.println(ident + ” ==> ” + re.getEventDefinition().getName());
      hasEvents = true;
      raiseAantal++;
    }
  }

  public boolean isParameterDefined(JobChainCall jc, String pName)
  {
    JobDefinitionParameter p = jc.getJobDefinition().getJobDefinitionParameterByName(pName);
    return (p != null);
  }

  public String getParameterValue(JobChainCall jc, String pName)
  {
    String valueParam = null;
    JobDefinitionParameter p = jc.getJobDefinition().getJobDefinitionParameterByName(pName);
    if (p != null)
    {
    if (jc.getJobChainCallInReferenceParameterByLocalJobDefinitionParameter(p) != null)
    {
      valueParam = “ref(” + jc.getJobChainCallInReferenceParameterByLocalJobDefinitionParameter(p).getSourceJobDefinitionParameter().getName() + “)”;
    }
    else
    {
      if (jc.getJobChainCallInExpressionParameterByLocalJobDefinitionParameter(p) != null)
      {
         valueParam = “expr(” + jc.getJobChainCallInExpressionParameterByLocalJobDefinitionParameter(p).getExpression() + “)”;
      }
      else
      {
        if (jc.getJobDefinition().getJobDefinitionParameterByName(pName).getDefaultExpression() != null)
        {
           valueParam = jc.getJobDefinition().getJobDefinitionParameterByName(pName).getDefaultExpression();
        }
        else
        {
           valueParam = “”;
        }
      }
     }
    }
    return valueParam;
  }

  public String buildParamList(String P_PARAMETERS, JobDefinition jd, JobChainCall ja)
  {
    String paramList  = null;
    String[] paramArray = P_PARAMETERS.split(“,”);
    for (int i = 0; i < paramArray.length; i++)
    {
      if (isParameterDefined(ja, paramArray[i]))
      {
        if (paramList == null)
        {
           paramList = “”;
        }
        paramList = paramList + “(” + paramArray[i] + “=” + getParameterValue(ja, paramArray[i]) + “) “;
      }
    }
    return paramList;
  }

  public void showChain(String P_PARAMETERS, String ident, JobDefinition jd)
  {
    String paramList = null;
    JobChain jc = jcsSession.getJobChainByJobDefinition(jd);
    if (jc != null)
    {
      for (Iterator it = jc.getJobChainSteps(); it.hasNext();)
      {
         JobChainStep js = (JobChainStep) it.next();

         jcsOut.println(ident + ” | “);
         if (it.hasNext())
         {
           jcsOut.println(ident + ” | ” + ” (step) “+ js.getName());
         }
         else
         {
           jcsOut.println(ident + ” + ” + ” (step) ” + js.getName());
         }
         for (Iterator it2 = js.getJobChainCalls(); it2.hasNext();)
         {
           JobChainCall ja = (JobChainCall) it2.next();
           paramList = null;
           JobChain jcc = jcsSession.getJobChainByJobDefinition(ja.getJobDefinition());
           paramList = buildParamList(P_PARAMETERS, jd, ja);
           paramList = paramList;

           String indent2 = ” |  “;
           if (jcc == null)
           {
              jcsOut.print(ident + ” +- ” + ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName());
              if (paramList != null)
              {
                 jcsOut.print(” ” + paramList);
              }
              if (ja.getJobDefinition().getTimeWindow() != null) {
                 jcsOut.print(” [” + ja.getJobDefinition().getTimeWindow().getName() + “]”);
              }
              jcsOut.println(“”);
              showEvents(ident + indent2, ja.getJobDefinition());
           }
           else
           {
              if (!chains.contains(ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName()))
              {
                chains.add(ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName());
                jcsOut.print(ident + ” +- ” + ” ” + ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName());
                if (paramList != null)
                {
                   jcsOut.print(” ” + paramList);
                }
                if (ja.getJobDefinition().getTimeWindow() != null) {
                   jcsOut.print(” [” + ja.getJobDefinition().getTimeWindow().getName() + “]”);
                }
                jcsOut.println(“”);
                showEvents(ident + indent2, ja.getJobDefinition());
                showChain(P_PARAMETERS, ident + indent2, ja.getJobDefinition());
              }
              else
              {
                jcsOut.print(ident + ” +- ” + ” *** ” + ja.getJobDefinition().getPartition().getName() + “.” + ja.getJobDefinition().getName() + ” ***”);
                if (paramList != null)
                {
                   jcsOut.print(” ” + paramList);
                }
                if (ja.getJobDefinition().getTimeWindow() != null) {
                   jcsOut.print(” [” + ja.getJobDefinition().getTimeWindow().getName() + “]”);
                }
                jcsOut.println(“”);
              }
           }
           if (it2.hasNext())
           {
             jcsOut.println(ident + ” |”);
           }
        }
     }
   }
  }

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. Zameer Ahamad

    Hi Experts,

    Please anyone can look into my request.

    We need to pull the report in excel or csv for the job definition which contains multiple times in single chain and it is having parameters with different values.

    Is it able to get all the details through any script or report to know all the values for the particular job definition parameters.

    (0) 
  2. Kshitish Mohanty

    Thanks Expert, the script is working perfectly in V9. However this is extracting whole chain detail existing in CPS.Can this be customized as follows:

    1- Can it be customized for only a single process chain?

    2-  Can it be customized to showcase all the ABAp parameter defined for each jobs defined inside the chain.

    3- Would be great if you can provide a script to extract the forecast report from cronacle which will include the queue, application and partition.

    Thanks a lot in advance!

    (0) 

Leave a Reply