cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CPS Batch script

former_member1244799
Participant
0 Kudos

Hi All,

Could you please advise.

I have a Windows batch script which runs in the last step of a job chain which checks whether the file exists or not. If exists, it returns ZERO return code and control goes to the previous Step 2 to Run a ABAP program.(using final status handlers ON COMPLETED: GOTO STEP 2).

If the file don't exist, the last step returns the NON-ZERO returns code and the last step gets errored which stops the control to previous Step 2. The chain is marked as completed as I have defined the final status handlers on the last step: ON ERROR: MARK CHAIN AS COMPLETED.

Could you please advise how can I make the last step as successful even though the file exists or not. Also In this scenario, if the file don't exist,  I have to stop the looping.

Thank you in advance.

Regards,

Ramana

Accepted Solutions (1)

Accepted Solutions (1)

nanda_kumar21
Active Contributor
0 Kudos

You current design is already perfect without being very complex, however, the looping solution seems a bit dangerous. I would totally avoid that and run the job every few minutes instead.

If you want to further simplify,

  • add a file event for the file
  • add a post running action on the ABAP job definition to check if the event isRaised().
    • if yes, clear the event.
    • if no, restart the job.

you will not need a job chain in this case. but beware, this will cause an infinite loop until a file is created.

thanks

Nanda

former_member1244799
Participant
0 Kudos

Hi Nanda,

I  can't use the file events as I am getting the files from a windows share where the agent is not installed. Also the job has to run at a specific time. I am using the job chain because there were few more steps which runs before the abap run.

I have resolved the issue by defining the below post running action at the job definition level on last step.

I re-defined the last step which check for the file. If the file exist it returns non zero return code and the below post running action executes and marks the last step as successful and re submits the job chain. With this way I am able to resubmit the job again if the file exists with out erroring the last step.

{
JobDefinition jd = jcsJob.getJobDefinition();
// Only run for user defined job definitions
if (jd.getBehavior().longValue() == 0)
{
// Will contain ReturnCodeMapToWarning parameter if it exists
JobParameter jp;
// Will contain the range of codes to map to warning.
String mapToWarning;
// Is it in the range.
boolean inRange;
Long returnCode;
// Look for the ReturnCodeMapToWarning parameter
jp = jcsJob.getJobParameterByName("ReturnCodeMapToWarning");
if (jp == null)
{
//Job parameter does not exist, do nothing
mapToWarning = null;
}
else
{
mapToWarning = jp.getInValueString();
}
// Only do mapping if there is a sensible value
if (mapToWarning != null && mapToWarning.length() >= 0)
{
returnCode = jcsJob.getReturnCode();
if (returnCode == null)
{
// Handle null as 0
returnCode = new Long(0);
}
// Use jcsSession.inRange to determine if the code is in range.
if (jcsSession.inRange(returnCode.intValue(), mapToWarning))
{
JobNote jn = jcsJob.createJobNote();
jn.setText("Setting status to Completed as "
+ jcsJob.getReturnCode()
+ " is in "
+ mapToWarning);
jcsPostRunningContext.setFinalStatus(JobStatus.Completed);
{
// code to submit a job running System_Info
// get the job definition
JobDefinition aJobDef = jcsSession.getJobDefinitionByName("JOBCHAIN_TEST2");
// create the job from the job definition
Job aJob = aJobDef.prepare();

}

}
}
}
}

Regards,

Ramana

former_member1244799
Participant
0 Kudos

Thank you Nanda. Your suggestions always helps me.

Regards,

Ramana

Answers (1)

Answers (1)

former_member1244799
Participant
0 Kudos


Hi All,

Below is thee code which I am using.

-------------------------------------------------------------------------------------------------------------------------

if not exist \\server1\INTRPTS\test.txt exit /b 2

exit /b  0

--------------------------------------------------------------------------------------------------------------------------------

Regards,

Ramana