Skip to Content

Creating a Job Chain in BPA via scripting fails

I try to create a simple Job Chain in BPA but it falis when I try to set the step parameters

{

String pPartition = "GLOBAL";
String jdName = "MyJobChainWithPreconditionABAP";
String stepName = "Step1"; try
{
//Get or create a partition (here we create one if it does not already exist)
Partition partition = jcsSession.getPartitionByName(pPartition);
if (partition == null)
{
partition = jcsSession.createPartition();
partition.setName(pPartition);
}
jcsOut.println("- Use partition " + pPartition); //Check if Job Definition of type JOB_CHAIN (chain definition) already exists
jcsOut.println("- Check if Job Definition " + jdName + " exists!");
JobDefinition jDefinition = jcsSession.getJobDefinitionByName(partition, jdName);
if (jDefinition == null)
{
//Create JobDefinition of type JOB_CHAIN (chain definition)
jcsOut.println("- JobDefinition " + jdName + " does not exists and will be created!");
jDefinition = jcsSession.createJobDefinition();
jDefinition.setName(jdName);
jDefinition.setJobDefinitionType(jcsSession.getJobDefinitionTypeByName(JobDefinitionType.JOB_CHAIN));
jDefinition.setPartition(partition); //Create JobChain object with one step and one job chain call
jcsOut.println("- Create JobChain object with one step and one job chain call");
JobChain jchain = jcsSession.createJobChain();
jchain.setJobDefinition(jDefinition); //Create Step
jcsOut.println("- Create Step");
JobChainStep jcstep = jchain.createJobChainStep();
jcstep.setSequenceNumber(Long.valueOf(0));
jcstep.setName(stepName); //Job chain call
jcsOut.println("- Create job chain");
JobChainCall jccall = jcstep.createJobChainCall(); // Set Step parameter
jcsOut.println("- Set Step parameter for SAP_AbapRun");
JobDefinition jDefinitionStep = jcsSession.getJobDefinitionByName("SAP_AbapRun");
Job process = jDefinitionStep.prepare();
process.getJobParameterByName("SAP_SYSTEMS").setInValueString("XXX");
process.getJobParameterByName("CLIENT").setInValueString("010");
process.getJobParameterByName("ABAP_PROGRAM_NAME").setInValueString("Z_TST_IDLE");
process.getJobParameterByName("JOBNAME").setInValueString("Step1");
process.getJobParameterByName("LANGUAGE").setInValueString("EN");

Queue queue = jcsSession.getQueueByName(partition, "XXX_Queue");
jcsOut.println("- Queue: " + queue);
process.setQueue(queue);

// Assign Parameters
jcsOut.println("- Assign Parameters");
jccall.setJobDefinition(jDefinitionStep);
jccall.setSequenceNumber(Long.valueOf(0)); }
else
{
jcsOut.println("JobDefinition " + jdName + " exists!");
jcsOut.println("You can change the JobDefinition name on the line:\n String jdName = \"MyJobChainWithPrecondition\";");
}
// Commit Changes
jcsOut.println("- Commit Changes");
jcsSession.persist(); // Script successfully finished
jcsOut.println("- Script successfully finished");
}
catch (Exception e)
{
jcsErr.println(e.getMessage());
throw e;
}
}

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Sep 12, 2018 at 06:00 PM

    Hello,

    Somewhere at the place of adding the definition to the call, you take the wrong path. Something more like this:

    {
      String pPartition = "GLOBAL";
      String jdName = "MyJobChainWithPreconditionABAP";
      String stepName = "Step1";
      try
      {
        //Get or create a partition (here we create one if it does not already exist)
        Partition partition = jcsSession.getPartitionByName(pPartition);
        if (partition == null)
        {
          partition = jcsSession.createPartition();
          partition.setName(pPartition);
        }
        jcsOut.println("- Use partition " + pPartition); //Check if Job Definition of type JOB_CHAIN (chain definition) already exists
        jcsOut.println("- Check if Job Definition " + jdName + " exists!");
        JobDefinition jDefinition = jcsSession.getJobDefinitionByName(partition, jdName);
        if (jDefinition == null)
        {
          //Create JobDefinition of type JOB_CHAIN (chain definition)
          jcsOut.println("- JobDefinition " + jdName + " does not exists and will be created!");
          jDefinition = jcsSession.createJobDefinition();
          jDefinition.setName(jdName);
          jDefinition.setJobDefinitionType(jcsSession.getJobDefinitionTypeByName(JobDefinitionType.JOB_CHAIN));
          jDefinition.setPartition(partition); //Create JobChain object with one step and one job chain call
          jcsOut.println("- Create JobChain object with one step and one job chain call");
          JobChain jchain = jcsSession.createJobChain();
          jchain.setJobDefinition(jDefinition); //Create Step
          jcsOut.println("- Create Step");
          JobChainStep jcstep = jchain.createJobChainStep();
          jcstep.setSequenceNumber(Long.valueOf(0));
          jcstep.setName(stepName); //Job chain call
          jcsOut.println("- Create job chain");
          JobChainCall jccall = jcstep.createJobChainCall(); // Set Step parameter
          jcsOut.println("- Set Step parameter for SAP_AbapRun");
          JobDefinition jDefinitionStep = jcsSession.getJobDefinitionByName("SAP_AbapRun");
          jccall.setJobDefinition(jDefinitionStep);
          jccall.setSequenceNumber(Long.valueOf(0));
          JobChainCallInExpressionParameter jcciep = jccall.createJobChainCallInExpressionParameter();
          jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("SAP_SYSTEMS");
          jcciep.setExpression("XXX");
          jcciep = jccall.createJobChainCallInExpressionParameter();
          jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("CLIENT");
          jcciep.setExpression("010");
          jcciep = jccall.createJobChainCallInExpressionParameter();
          jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("ABAP_PROGRAM_NAME");
          jcciep.setExpression("Z_TST_IDLE");
          jcciep = jccall.createJobChainCallInExpressionParameter();
          jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("JOBNAME");
          jcciep.setExpression("Step1");
          jcciep = jccall.createJobChainCallInExpressionParameter();
          jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("LANGUAGE");
          jcciep.setExpression("EN");
    
    
          Queue queue = jcsSession.getQueueByName(partition, "XXX_Queue");
          jcsOut.println("- Queue: " + queue);
          JobChainCallSchedulingParameter jccsp = jccall.createJobChainCallSchedulingParameter();
          jccsp.setName(SchedulingParameterName.Queue);
          jccsp.setExpression(queue.getBusinessKey().getPath().toString());
        }
        else
        {
          jcsOut.println("JobDefinition " + jdName + " exists!");
          jcsOut.println("You can change the JobDefinition name on the line:\n String jdName = \"MyJobChainWithPrecondition\";"); 
        }
        // Commit Changes
        jcsOut.println("- Commit Changes");
        jcsSession.persist(); // Script successfully finished
        jcsOut.println("- Script successfully finished");
      }
      catch (Exception e)
      {
        jcsErr.println(e.getMessage());
        throw e;
      }
    }
    

    Regards Gerben

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 13, 2018 at 07:38 AM

    Hello Gerben

    Many thanks for your really fast response and help. I was able to create the Job Chain sucessfully with your code example.

    I fixed just a few syntax errors and jcciep.createJobChainCallSchedulingParameter to jccall.createJobChainCallSchedulingParameter().

    This is the corrected and working code:

    {
    String pPartition = "GLOBAL";
    String jdName = "MyJobChainWithPreconditionABAP";
    String stepName = "Step1";
    try
    {
    //Get or create a partition (here we create one if it does not already exist)
    Partition partition = jcsSession.getPartitionByName(pPartition);
    if (partition == null)
    {
    partition = jcsSession.createPartition();
    partition.setName(pPartition);
    }
    jcsOut.println("- Use partition " + pPartition); //Check if Job Definition of type JOB_CHAIN (chain definition) already exists
    jcsOut.println("- Check if Job Definition " + jdName + " exists!");
    JobDefinition jDefinition = jcsSession.getJobDefinitionByName(partition, jdName);
    if (jDefinition == null)
    {
    //Create JobDefinition of type JOB_CHAIN (chain definition)
    jcsOut.println("- JobDefinition " + jdName + " does not exists and will be created!");
    jDefinition = jcsSession.createJobDefinition();
    jDefinition.setName(jdName);
    jDefinition.setJobDefinitionType(jcsSession.getJobDefinitionTypeByName(JobDefinitionType.JOB_CHAIN));
    jDefinition.setPartition(partition); //Create JobChain object with one step and one job chain call
    jcsOut.println("- Create JobChain object with one step and one job chain call");
    JobChain jchain = jcsSession.createJobChain();
    jchain.setJobDefinition(jDefinition); //Create Step
    jcsOut.println("- Create Step");
    JobChainStep jcstep = jchain.createJobChainStep();
    jcstep.setSequenceNumber(Long.valueOf(0));
    jcstep.setName(stepName); //Job chain call
    jcsOut.println("- Create job chain");
    JobChainCall jccall = jcstep.createJobChainCall(); // Set Step parameter
    jcsOut.println("- Set Step parameter for SAP_AbapRun");
    JobDefinition jDefinitionStep = jcsSession.getJobDefinitionByName("SAP_AbapRun");
    jccall.setJobDefinition(jDefinitionStep);
    jccall.setSequenceNumber(Long.valueOf(0));
    JobChainCallInExpressionParameter jcciep = jccall.createJobChainCallInExpressionParameter();
    jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("SAP_SYSTEMS"));
    jcciep.setExpression("XXX");
    jcciep = jccall.createJobChainCallInExpressionParameter();
    jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("CLIENT"));
    jcciep.setExpression("010");
    jcciep = jccall.createJobChainCallInExpressionParameter();
    jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("ABAP_PROGRAM_NAME"));
    jcciep.setExpression("Z_TST_IDLE");
    jcciep = jccall.createJobChainCallInExpressionParameter();
    jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("JOBNAME"));
    jcciep.setExpression("Step1");
    jcciep = jccall.createJobChainCallInExpressionParameter();
    jcciep.setLocalJobDefinitionParameter(jDefinitionStep.getJobDefinitionParameterByName("LANGUAGE"));
    jcciep.setExpression("EN");
    Queue queue = jcsSession.getQueueByName(partition, "XXX_Queue");
    jcsOut.println("- Queue: " + queue);

    JobChainCallSchedulingParameter jccsp = jccall.createJobChainCallSchedulingParameter();
    //JobChainCallSchedulingParameter jccsp = jcciep.createJobChainCallSchedulingParameter();
    jccsp.setName(SchedulingParameterName.Queue);
    jccsp.setExpression(queue.getBusinessKey().getPath().toString());
    }
    else
    {
    jcsOut.println("JobDefinition " + jdName + " exists!");
    jcsOut.println("You can change the JobDefinition name on the line:\n String jdName = \"MyJobChainWithPrecondition\";");
    }
    // Commit Changes
    jcsOut.println("- Commit Changes");
    jcsSession.persist(); // Script successfully finished
    jcsOut.println("- Script successfully finished");
    }
    catch (Exception e)
    {
    jcsErr.println(e.getMessage());
    throw e;
    }
    }


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.