cancel
Showing results for 
Search instead for 
Did you mean: 

JOB Chain Name

former_member1244799
Participant
0 Kudos

Hi All,

Could you please help on the below query.

I have a below job chain 'JOBCHAIN_ALERT' with 2 steps.

Example:

JOBCHAIN_ALERT :

Step 1

Job1

Step 2

Job 2

I am re-submitting the Job chain 'JOBCHAIN_ALERT' at job definition level in post running action of Job2  using the below code.

JobDefinition aJobDef = jcsSession.getJobDefinitionByName("JOBCHAIN_ALERT");

// create the job from the job definition

Job aJob = aJobDef.prepare();

Instead of hard coding the job chain name in the post running action. How can I dynamically get the job chain name and submit it.

Thank you in advance.

Regards,

Ramana

Accepted Solutions (0)

Answers (1)

Answers (1)

gmblom
Active Contributor
0 Kudos

Hello,

Before I give you the answer, why are you doing this? Why are not not using a submit frame on the job chain itself, or use the restart behavior of the job chain? This is all built in techniques which are probably much more reliable than custom coding.

Regards Gerben

former_member1244799
Participant
0 Kudos

Hello Gerben,

Below is my requirement. This job has to run at a specific time daily.

1. Checks if the file is created. If the file is created..continues to step 2. Else the step should error.

2. Run the ABAP program

3.This step checks again any more files exists. If the files exist..step2 should run again...If the file don't exist, job should not error. The looping needs to be done until there are no more files left. After no more files left, then the job should run next day.

File check is done on a windows share where there is no agent installed. For this scenario, I am not able to use the final status handlers as the step 3 should not error if there is no file.

So I wrote a post running action on the job definition level of step 3.

In the step 3, I wrote a windows command which checks for the file. If not exist....returns a zero return code and the job is marked as successfully completed.

If the step 3 returns a non zero return code for the file exist. Then in the post running action. I am marking the step 3 as completed and resubmitting the job chain using the above code.

Please advise.

Regards,

Ramana

gmblom
Active Contributor
0 Kudos

Hello Ramana,

There are two options:

1) you set an additional Final Status Handler on Step 1: On Error -> Set Chain Completed

     and on Step 2: On Completed -> Goto Step 1

2) if you want to make a distinction between if there was no file at all (Error in Step 1) or no additional files (Error in Step 3) you can use the same technique, but keep everything as it is, but use the same definition from Step 1 also in Step 3 and use Final Status Handlers in Step 3: On Error -> Set Chain Completed and On Completed -> Goto Step 2

No need for coding here.

Regards Gerben

former_member1244799
Participant
0 Kudos

Hi Gerben,

Thank you so much.

Step 1: We want to put this step into error only if the intial file won't exist and subsequently the job chain status to error, So that the chain will not continue.


Step 3: When this step checks for the second file, if the file don't exist, we want to put this step into successfull status as well as the job chain status. If the file exists..mark this step as successful and continue to the step 2 to run the ABAP program.

So I have used postrunning action in step 3.

Please advise.

Regards,

Ramana

gmblom
Active Contributor
0 Kudos

Hello Ramana,

So you can use my advice from the previous comment:

Step 3: On Error -> Set Chain Completed and On Completed -> Goto Step 2

Dont care about the Error status of Step 3, using the final status handler you set the chain status to Completed anyway.

Regards Gerben

former_member1244799
Participant
0 Kudos


Hi Gerben,

I configured the jobs intially using the steps which you specified. I set the job chain as completed if the file is not present.  But my Manager don't want the third step to be errored for the second iteration if the file is not present . So I did this through coding to make the step as successful eventhough the file don't exist.

Regards,

Ramana

gmblom
Active Contributor
0 Kudos

Hello Ramana,

With all due respect I do not agree to that approach. Why choose customizing over build in functionality? The third step errors correctly: the file is not there, and that is what you check for. And also you handle the Error appropriately as well: you finish processing and the top level process completes correctly. I do not see any harm in this.

If, for arguments sake, this causes false positives in the alerting or monitoring, then you just have to adjust that process and tweak the procedures around error handling from a monitoring perspective.

Regards Gerben

former_member1244799
Participant
0 Kudos

Thank you so much Gerben,

I like your replies. I try to go through each and every discussion of yours which helped me to get some good knowledge. When I started using this forum, I don't know anything. It has taken me to a place where I am able to install the agents and configure some critical jobs. Apart from Admin guide, this is the only place where I learn CPS. I am very much grateful to this forum especially you, Carpenter, Nanda Asif, Gurbaksh and many more.


I am sorry to be not much clear on this.

This job runs every day at 5pm. Some times if the file arrives late, there will be two files for next day(which happens once in a while). Then next day this job has to run for two times for these two files.

Actually we have only one file everyday (unless the file arrives late for the previous job run).

I configured the jobs as you advised.

When ever this job runs at 5pm, the first step looks for the file . If it won't find, the step should error and also the job should fail. Client is ok with this one.

The third step checks for any more files remaining and it errors every day as we have only one file daily.

I kept the job chain status to completed if the third step errors. But the client don't want step 3 to error if the file don't exist as the second file exist only once in a while. I am not able to convince them with the build in functionality.

Please advise.


Regards,
Ramana