Examples and Code Samples

This page presents various examples for how to create conversion rules with the Control-M Self-Conversion API.

Input Data Sample

All examples on this page are based on the following sample XML input data, which you plan to convert to Control-M data.

Copy
<BOX DATACENTER="DS" Box_Name="Box1">
<JOB Name="JOB1" UserName="USER1" Group="ICA" Type="OS" Command="c:\test1.bat" />
<JOB Name="JOB2" UserName="USER1" Group="ICA" Type="OS" Command="c:\test2.bat" />
<JOB Name="JOB3" UserName="USER1" Group="ICA" Type="OS" Command="c:\test3.bat" />
<JOB Name="JOB4" UserName="USER1" Group="ICA" Type="SAP" >
<saptask>
<jobname>SAP_TEST</jobname>
<stepcount>1</stepcount>
<steps>
<step>
<stepid>1</stepid>
<type>ABAP</type>
<abap>
<params>Z_00497_US_CHG</params>
<varientvalue>VARIANT1</varientvalue>
<abapprogram>ZPAO_JJ_WILMA_OUTBOUND</abapprogram>
</abap>
</step>
</steps>
</saptask>
</JOB>
<JOB Name="JOB5" UserName="USER1" Group="ICA" Type="MFT" >
<transfer>
<tranfertype>BINARY</tranfertype>
<source>"C:\x.exe"</source>
<destination>"C:\target\"</destination>
</transfer>
<transfer>
<tranfertype>ASCII</tranfertype>
<source>"C:\y.txt"</source>
<destination>"D:\target_y.txt"</destination>
</transfer>
</JOB>
<JOB Name="JOB6" UserName="USER1" Group="ICA" Type="SAPBW"  >
<saptask>
<type>ProcessChain</type>
<ProcessChain>
<ID>Process Chain ID</ID>
<Description>Process Chain Description</Description>
<RerunOption>FromStart</RerunOption>
</ProcessChain>
</saptask>
</JOB>
<Dependency FromJOB="JOB1" ToJob="JOB2" ></Dependency>
<Dependency FromJOB="JOB2" ToJob="JOB3" ></Dependency>
<Dependency FromJOB="JOB2" ToJob="JOB4" ></Dependency>
<Dependency FromJOB="JOB3" ToJob="JOB5" ></Dependency>
<Dependency FromJOB="JOB4" ToJob="JOB5" ></Dependency>
<Dependency FromJOB="JOB5" ToJob="JOB6" ></Dependency>
</BOX>

Creating a Folder

The following example demonstrates how to create a Control-M Folder from every XML element with tag name BOX in the input data.

Copy
//  ---- Create Folder Rule ----
// XPath query of the XML element we look for in XML Input Data
String xpathQuery = "//BOX";
 
// Retrieve all elements with tag name equals to "BOX" XML elements into folderElements  list
List<CtmXmlElement> folderElements  = ctmXmlQuery.findXmlElementsByXPath(xpathQuery);
 
// Run in a loop on all elements with tag name equals to "BOX" XML elements found,
// and create a Control-M Folder for each one of them
// For each Control-M Folder created we keep the equivalent XML element data
for(CtmXmlElement folderElement : folderElements ) {
CtmFolder ctmFolder = ctmWorkspace.createFolder(folderElement);
}

Setting a Name for a Folder

The following example demonstrates how to set the name of a Control-M Folder to the value of the XML attribute BOX_NAME in the BOX element.

Copy
// ---- Folder Name Rule ----
// Retrieve from the ctmWorkspace all the Control-M folders defined in the previous rule
// For each ctmFolder object, retrieve the equivalent XML data
// And from each folder XML data, retrieve the value of attribute "BOX_NAME"
// and assign it to the Control-M folder name attribute
 
ctmWorkspace.getAllFolders().each{ ctmFolder ->
CtmXmlElement folderElement = ctmFolder.getFolderInputXmlData();
String folderName = folderElement.getAttribute("Box_Name");
ctmFolder.general().setName(folderName);
}

Creating a Job

The following example demonstrates how to create a Control-M job from every XML element with tag name JOB in the input data.

Copy
//  ---- Create Job Rule ----
// XPath query of the XML element we look for in XML Input Data
String xpathQuery = "//JOB";
 
// Retrieve all elements with tag name equals to "JOB" XML elements into jobElements list
List<CtmXmlElement> jobElements = ctmXmlQuery.findXmlElementsByXPath(xpathQuery);
 
// Run in a loop on all elements with tag name equals to "JOB" XML elements found,
// and create a Control-M Job for each one of them
// For each Control-M Job created we keep the equivalent XML element data
for(CtmXmlElement jobElement : jobElements) {
CtmJob ctmJob = ctmWorkspace.createJob(jobElement);
}

Setting a Name for a Job

The following example demonstrates how to set the name of a Control-M job to the value of the XML attribute Name in the BOX element.

Copy
// ---- Job Name Rule ----
// For each Control-M Job created we get the value of attribute name "Name" from
// the equivalent XML element data and set the value to be the Job name
 
String argument = "Name";
ctmWorkspace.getAllJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String jobName = jobElement.getAttribute(argument);
ctmJob.general().setName(jobName);
}

Linking a Job to a Folder

The following example demonstrates how to link a job to a folder according to the parent XML element named BOX.

Copy
// ---- Link job to folder Rule ----
 
String argument = "BOX";
def jobsList = ctmWorkspace.getAllJobs();
jobsList.each  { ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
CtmXmlElement parentElement = jobElement.getParent();
if(parentElement != null && parentElement.getTagName().equals(argument))
{
CtmFolder ctmFolder = ctmWorkspace.getFolder(parentElement);
ctmWorkspace.insertJobToFolder(ctmJob, ctmFolder);
}
}

Setting OS job type

The following example demonstrates how to set job type to OS job when it contains the XML attribute Type with value OS.

Copy
// ---- Create Os Job rule ----
String argument = "Type";
ctmWorkspace.getAllJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String attributeValue = jobElement.getAttribute(argument);
if(attributeValue != null && attributeValue.equals("OS")){
ctmJob.setOsType();
}
}

Setting OS Job Command Line

The following example demonstrates how to set the Control-M OS job's command line to the value of the XML attribute Command in the BOX element.

Copy
// ---- Create Os Command Rule ----
String argument = "Command";
ctmWorkspace.getOsJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String command = jobElement.getAttribute(argument);
ctmJob.general().osParameters().setCommand(command);
}

Setting a Job Application

The following example demonstrates how to set a job application according to the value of the XML attribute Group in the BOX element.

Copy
// ---- Create Job Application Rule ----
String argument = "Group";
ctmWorkspace.getAllJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String applicationValue = jobElement.getAttribute(argument);
ctmJob.general().setApplication(applicationValue);
}

Setting SAPR3 Job Type

The following example demonstrates how to set job type to SAPR3 job when it contains the XML attribute Type with value SAP.

Copy
// ---- Create SapR3 Job rule ----
String argument = "Type";
ctmWorkspace.getAllJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String attributeValue = jobElement.getAttribute(argument);
if(attributeValue != null && attributeValue.equals("SAP")){
ctmJob.setSapR3Type();
}
}

Setting SAPR3 Job Name

The following example demonstrates how to set an SAP job name to Control-M for SAP R3 jobs from the input data.

Copy
// ---- Create SapR3 job name Rule ----
String xpathQuery = "saptask";
ctmWorkspace.getSapR3Jobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
List<CtmXmlElement> ctmXmlElementResult = jobElement.getDirectChildsElementbyName(xpathQuery);
for(CtmXmlElement ctmXmlElement : ctmXmlElementResult) {
CtmXmlElement sapJobNameElement = ctmXmlElement.getFirstChildElementByName("jobname");
ctmJob.general().sapR3Parameters().setSAPJobName(sapJobNameElement.getText());
}
}

Setting SAPR3 Connection Profile

The following example demonstrates how to set an SAP connection profile to Control-M for SAP R3 jobs from the input data.

Copy
// ---- Create SapR3 ConnectionProfile Rule ----
String argument = "UserName";
ctmWorkspace.getSapR3Jobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String connectionProfileValue = jobElement.getAttribute(argument);
ctmJob.general().sapR3Parameters().setConnectionProfile(connectionProfileValue);
}

Setting SAPR3 Action

The following example demonstrates how to set an SAP action to Control-M for SAP R3 jobs.

Copy
// ---- Create SapR3 Action Rule ----
ctmWorkspace.getSapR3Jobs().each{ ctmJob ->
ctmJob.general().sapR3Parameters().setAction(SapR3Action.CreateANewJob);
}

Setting SAPR3 ABAP Step Attributes

The following example demonstrates how to set SAP R3 ABAP step attributes to Control-M for SAP R3 jobs from the input data.

Copy
//---- Create SapR3 abap Rule ----
String xpathQuery = "abap";
ctmWorkspace.getSapR3Jobs().each{ ctmJob ->
CtmXmlElement jobElement  = ctmJob.getJobInputXmlData();
List<CtmXmlElement> abapXmlElements = jobElement.getAllDecnedElementByName(xpathQuery);
for(CtmXmlElement abapXmlElement : abapXmlElements) {
String variant = abapXmlElement.getFirstChildElementByName("varientvalue").getText();
String abapProgram = abapXmlElement.getFirstChildElementByName("abapprogram").getText();
SapR3AbapStepAPI step = ctmJob.general().sapR3Parameters().addAbapStep();
step.setAbapProgramName(abapProgram);
step.setVariantName(variant);
}
}

Setting File Transfer Job Type

The following example demonstrates how set job type to a File Transfer job when it contains the XML attribute Type with value MFT.

Copy
// ---- Create FileTransfer Job rule ----
String argument = "Type";
ctmWorkspace.getAllJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String attributeValue = jobElement.getAttribute(argument);
if(attributeValue != null && attributeValue.equals("MFT")){
ctmJob.setFileTransferType();
}

Setting File Transfer Connection Profile

The following example demonstrates how to set a File Transfer connection profile to Control-M File Transfer jobs from the input data.

Copy
// ---- Create FileTransfer ConnectionProfile Rule ----
String argument = "UserName";
ctmWorkspace.getFileTransferJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String connectionProfileValue = jobElement.getAttribute(argument);
ctmJob.general().fileTransferParameters().setConnectionProfile(connectionProfileValue);
}

Setting File Transfer Attributes

The following example demonstrates how to set File Transfer attributes to Control-M for File Transfer jobs from the input data.

Copy
// ---- Create FileTransfer transfer Rule ----
String xpathQuery = "transfer";
ctmWorkspace.getFileTransferJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
List<CtmXmlElement> transferXmlElements = jobElement.getDirectChildsElementbyName(xpathQuery);
for(CtmXmlElement transferElement : transferXmlElements) {
String tranfertype = transferElement.getFirstChildElementByName("tranfertype").getCData();
String leftPath = transferElement.getFirstChildElementByName("source").getCData();
String rightPath = transferElement.getFirstChildElementByName("destination").getCData();
CtmTransfer transfer = ctmJob.general().fileTransferParameters().addNewTransfer();
transfer.setRightPath(rightPath);
transfer.setLeftPath(leftPath);
if(tranfertype != null && tranfertype.equals("BINARY")){
transfer.setTransferType(TransferType.Binary);
}else{
transfer.setTransferType(TransferType.Ascii);
}
transfer.setTransferOption(TransferOption.Filewatch_And_Transfer_from_left_to_right);
}
}

Setting SAP BW Job Type

The following example demostrates how to set the job type to an SAP BW job when it contains the XML attribute Type with the value SAPBW.

Copy
//  ---- Create SapBW Job rule ----
String argument = "Type";
ctmWorkspace.getAllJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String attributeValue = jobElement.getAttribute(argument);
if(attributeValue != null && attributeValue.equals("SAPBW")){
ctmJob.setSapBWType();
}
}

Setting SAP BW Connection Profile

The following example demonstrates how to set an SAP connection profile to Control-M for SAP BW jobs from the input data.

Copy
// ---- Create SapBW Connection Profile Rule ----
String argument = "UserName";
ctmWorkspace.getSapBWJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
String connectionProfileValue = jobElement.getAttribute(argument);
ctmJob.general().sapBWParameters().setConnectionProfile(connectionProfileValue);
}

Setting SAP BW Process Chain Parameters

The following example demonstrates how to set the SAP BW Process Chain parameters to Control-M for SAP BW jobs.

Copy
//---Create SAP BW Process Chain Rule ---
ctmWorkspace.getSapBWJobs().each{ ctmJob ->
CtmXmlElement jobElement = ctmJob.getJobInputXmlData();
List<CtmXmlElement> ctmXmlElementResult = jobElement.getAllDecnedElementByName("type");
for(CtmXmlElement ctmXmlElement : ctmXmlElementResult)
{
String type = ctmXmlElement.getText();
if (type != null && type.equals("ProcessChain"))
{
CtmXmlElement processChainElement = jobElement.getAllDecnedElementByName("ProcessChain").get(0);
if (processChainElement != null)
{
ctmJob.general().sapBWParameters().setProcessType(SapBWProcessType.ProcessChain);
CtmXmlElement idElement = processChainElement.getFirstChildElementByName("ID");
if (idElement != null)
ctmJob.general().sapBWParameters().setID(idElement.getText());
CtmXmlElement descElement = processChainElement.getFirstChildElementByName("Description");
if (descElement != null)
ctmJob.general().sapBWParameters().setDescription(descElement.getText());
CtmXmlElement rerunOptionElement = processChainElement.getFirstChildElementByName("RerunOption");
if (rerunOptionElement != null)
{
String rerunOption = rerunOptionElement.getText();
if (rerunOption.equals("FromStart"))
ctmJob.general().sapBWParameters().setReRunOption(SapBWRerunOption.RerunFromStart);
}
}
}
}
}

Setting Jobs In Event

The following example demonstrates how to add Jobs In Events from the input data.

Copy
// ---- Create In Condition Rule ----
def jobsList = ctmWorkspace.getAllJobs();
jobsList.each { ctmJob ->
String targetJob = ctmJob.general().getName();
// Retrieve all Dependency elements that contain current job name in "ToJob" attribute
String xpathQuery = "//Dependency[@ToJob=\"" + targetJob + "\"]";
List<CtmXmlElement> dependenciesXmlElements = ctmXmlQuery.findXmlElementsByXPath(xpathQuery);
for(CtmXmlElement dependencyElement: dependenciesXmlElements)
{
// Get the source job name
String sourceJob = dependencyElement.getAttribute("FromJOB");
// Build condiiton name in {SourceJob-To-TagetJob} pattern
String inConditionName = sourceJob + "-TO-" + targetJob;
ctmJob.prerequisites().addInCondition(inConditionName);
}
}

Setting Jobs Out Event

The following example demonstrates how to add jobs Out Events from the input data.

Copy
// ---- Create Out Condition Rule ----
def jobsList = ctmWorkspace.getAllJobs();
jobsList.each { ctmJob ->
String sourceJob = ctmJob.general().getName();
// Retrieve all Dependency elements that contain current job name in "FromJob" attribute
String xpathQuery = "//Dependency[@FromJOB=\"" + sourceJob + "\"]";
List<CtmXmlElement> dependenciesXmlElements = ctmXmlQuery.findXmlElementsByXPath(xpathQuery);
for(CtmXmlElement dependencyElement: dependenciesXmlElements)
{
// Get the target job name
String targetJob = dependencyElement.getAttribute("ToJob");
// Build condiiton name in {SourceJob-To-TagetJob} pattern
String outConditionName = sourceJob + "-TO-" + targetJob;
ctmJob.actions().addOutCondition(outConditionName);
}
}