‎2010 Apr 14 6:28 PM
I am using the standard SAP Event SAP_NEW_PROCESS_MESSAGE to trigger a batch job.
However, when 3 messages come in, 3 jobs are triggered with the other 2 being cancelled by SAP since only 1 should run to avoid the same message being processed by the same program and while this 1 job is running and additional messages come in, another set of batch job runs but is automatically cancelled by SAP.
How do i avoid having 3 jobs running at the same time given that I am using the event trigger to run the job?
In SM36, when you put the Start Condition, you can only put 1 condition and not 2 conditions(Event and no other job is running).
If someone can help me with setting it up.
if I need to create a program, how will it be set up and what table do i need to read?
‎2010 Apr 14 8:19 PM
Hi,
instead of using event to trigger job can you try scheduling it to run periodically say 5 mins interval?
-Ramesh
‎2010 Apr 14 8:19 PM
Hi,
instead of using event to trigger job can you try scheduling it to run periodically say 5 mins interval?
-Ramesh
‎2010 Apr 14 8:29 PM
Hi,
We cannot schedule every 5 minutes because we need that the message is processed as soon as it is created for a realtime run.
Do you have other options?
Shirley
‎2010 Apr 14 8:51 PM
I assume you are trying to send the process messages as they got created in SAP.
and what is the error message that you are seeing when job cancels itself? is it "Preceding job not yet completed"?
-Ramesh
‎2010 Apr 14 9:08 PM
Ramesh,
You are 100% correct. I am sending new process message and the error message you indicated is exactly the error message.
Can you help me avoid having this as the cancelled jobs are sending out an email alerts(which are too many) and we don;t want our operations people to get that alert for this specific job but other jobs that are cancelling, we want the operators to get their alert.
If this cannot be avoided (multi jobs with others cancelling out). Do you know how to control the Email alert such that for this job it will not send out the CCMS alert for tracking Background\Aborted Jobs.
Thanks
Shirley
‎2010 Apr 14 9:16 PM
hi,
I think that is not possible.That is the reason we have set up to run this job every minute.
Even though some times(not very often) this job takes more than a min and subsequent job started after a min will fails with the error message that I gave.
I hope you also may have to do the same thing.
-Ramesh
‎2010 Apr 14 9:57 PM
Thanks Ramesh.
The business wants the we continue to run based on trigger. Would you know if by creating a program that will be trigger by the new process message and then call another job that will check if such job is not running yet to then submit the job is possible?
if yes, how?
Shirley
‎2010 Apr 14 10:14 PM
yes..you have to create a custom program to trigger the "actual job" if there is no "active actual job" running. If it is running then wait for until it is completed and run the "actual job".
-Ramesh
‎2010 Apr 14 11:41 PM
Hi Shirley,
SAP has the programs RSBTONEJOB and RSBTONEJOB2 to prevent multiple instances of the same job running. They have to be scheduled as a job step and you'll have to enter the program and variant that they should invoke. In case of another job instance already running, the first program terminates the job with an error message, whereas the second one simply exits the job without executing the program.
Most likely this doesn't fit your requirements, because they only guarantee that only one job instance is active, but they don't ensure that all the invoked jobs do the work they're supposed to do. So in your case with three events raised and then two events possibly getting their job stopped might result in data not getting processed. If you need that, then I think there's no standard program for that and you'd have to go with Ramesh's suggestion.
Cheers, harald
‎2010 Apr 15 2:37 PM
Hi Harald,
This sounds interesting.
What I have right now is just 1 job with a trigger event of SAP_NEW_PROCESS_MESSAGE. However, when 3 messages come in, the job is then triggered 3 times but the other 2 is immediately cancelled by SAP with an error message "Preceeding job is not yet complete" which is correct. The objective I am trying to achieve is if there are 3 or 4 messages that come in, I want that only 1 job runs and not 4 since the other 3 will be cancelled anyway and we have a CCMS alert that goes out for any cancelled job and this particular cancelled jobs are valid and we do not want to get an alert since 1 job is running and is enough to process the other 3 messages.
In your example, can you let me know who to set it up since you said it should be set up as a job step? The current Batch set up I have is
Job Name: Process_Message
Job Start Condition:
After Event
Event: SAP_NEW_PROCESS_MESSAGES
Step 1: program to run RCOCB002
If I were to use the 2 programs you indicated, can you let me know how I will set it up taking into account that the job is triggered by an event and I only want one job to run even if the trigger is 5(5 messages comes in almost at the same time) and not 5 of the same Job (Process_Message).
Shirley
‎2010 Apr 15 2:44 PM
Thanks Ramesh.
I was thinking how? Because my trigger would still be the new process message.
Will I then set it up as:
Job Name: Process_Message
Start Condition:
After Event: SAP_NEW_PROCESS_MESSAGE
Step 1: my custom program which will then invoke Job 2 below if job 2 is not yet running(but how?)
Job Name: Run_Message
Start Condition: What will this be?
Step 1: the real program that process the message (RCOCB002)
In the above example, the first job (Process_Message) will be triggered as new message comes in and maybe in my program I can just end if I see that job 2(Run_Message) normally without "cancellation" but how will i trigger Job 2(Run Message)?
Also, do you know the table that I can check to know that Job 2(Process_message) is running(Active)?
Shirley
‎2010 Apr 15 3:36 PM
Hi,
You can use this FM to create a job BP_JOB_CREATE with required steps.
You can use tables TBTCO/TBTCP t check the previous jobs. This needs to be done in custom program until the job is finished and once it is finished use the above FM to run the "actual job".
-Ramesh
‎2010 Apr 15 4:04 PM
Thanks Ramesh,
We are pretty new with the Batch job in SAP so if you can give me a sample of how I will set up the batch job?
Do I set up 2 or do i set up 1?
If you can like use the example I placed earlier.
Thanks!
‎2010 Apr 15 4:13 PM
The objective I am trying to achieve is if there are 3 or 4 messages that come in, I want that only 1 job runs and not 4 since the other 3 will be cancelled anyway \[..\]
Ok, so you could utilize program RSBTONEJOB2 for that.
\[..\] we do not want to get an alert since 1 job is running and is enough to process the other 3 messages.
Let me give a general comment without having looked at your specific example. In most cases I'd expect your statement to be wrong. E.g. let's assume like so many programs, you have one that selects relevant objects and then processes them. So by the time the 3 other events kick in, the first job might have finished selecting all the objects and is now processing them. Any new objects that were created since then would be simply ignored.
That's why I initially commented that I doubt that this is what you're looking for and it seemed to me that Ramesh's comment with the custom program waiting for the job to finish was right on track. Some further thought probably should go into such a solution, because I'd expect that you don't want to queue up more than one waiting job...
In your example, can you let me know who to set it up since you said it should be set up as a job step?
The program RSBTONEJOB2 is straightforward. If you look at the coding you'll see that it's really simple. It basically just checks how many jobs with the given name are running and only submits the given program with the variant if there is exactly one job.
So in your case you should redefined your job PROCESS_MESSAGE and replace the first step with an execution of program RSBTONEJOB2 with a variant using the following parameters:
JOBNAME : PROCESS_MESSAGE
REPORT : RCOCB002
Test it, check the job logs. You will see that RSBTONEJOB2 will effectively guarantee that only one job instance is running. It will not guarantee though that all the data gets processed as this might not work due to the suppression of additional jobs. However, you could use this program as a template and implement the additional waiting mechanism Ramesh described.
‎2010 Apr 15 4:23 PM
Thanks Harald.
I will set it up and change the step to run the program you mentioned to test. Does this mean that my Process_Message is the only job I need and I can continue to use the Trigger event "SAP_NEW_PROCESS_MESSAGE"? to trigger Process_Message job?
‎2010 Apr 15 5:18 PM
Hi Harald,
This seems to be a promising solution. It is okay for only 1 job to run since SAp in itself cancels the other jobs with an error saying, "Preceding job is not completed" instead of waiting so your concern that some records may not be processed is not the case since the current state we have they are not queued by SAP but immediately cancelled when it detects the one job is running.
The program that is being run is a BDC and does not select a set of data at the time of run but goes through the table as it runs.
‎2010 Apr 16 8:58 PM
Hi Harald,
I have set up the job Process_message to have the RSBTONEJOB2(with this calling the real program and checking on the job PROCESS_MESSAGE). My questions are:
1. I am still getting a "Cancelled" job when more than one ran and it is not finished, the other Process_Message job fails(Cancelled status which then sends out an email alert to our email). The job log error is still saying "Preceding job not yet completed". Why is that so?
2. The Process_Message job runs and in the job log it says OK, 1 job running but sometimes it says OK, 2 jobs running and the status is "Finished". When I see the message "OK, 2 jobs running" with a status of "Finished", what does that mean? That it actually DID NOT try to run the job(2nd job) because 1 is still active but did not abort the job that is why the status is Finished (which is what we want).
Again, our objective is to only run run job when the trigger happens while the other Process_Message job kicks in BUT will not really run the real program but without having a "Cancelled" status so we don't receive multiple email alerts.
Thanks!
Shirley
‎2010 Apr 16 9:03 PM
Harald,
THe other question I have is if there are 5 Process_Message jobs that got triggered and try to run, will RSBTONEJOB2 keep one job running while the other 4 will stop running (but will not have a status of cancelled)?
Thanks and hoping to receive feedback from you for the 3 questions I sent out
Shirley
‎2010 Apr 17 8:59 AM
So let me try to answer your questions:
1. I am still getting a "Cancelled" job when more than one ran and it is not finished, the other Process_Message job fails(Cancelled status which then sends out an email alert to our email).
Weird. If you have setup the PROCESS_MESSAGE job like I described below, where you only invoke the RSBTONEJOB2 as the only step, this shouldn't happen. I could see possible problems in a case where you invoke via RSBTONEJOB2 a program that schedules another job or kick off some asynchronous task. However, in that case one would expect that the error should show up somewhere else, not in the PROCESS_MESSAGE job. Your question 2 though seems to indicate that it works?!
2. The Process_Message job runs and in the job log it says OK, 1 job running but sometimes it says OK, 2 jobs running and the status is "Finished". When I see the message "OK, 2 jobs running" with a status of "Finished", what does that mean? That it actually DID NOT try to run the job(2nd job) because 1 is still active but did not abort the job that is why the status is Finished (which is what we want).
This is basically what RSBTONEJOB2 does: It checks how many instances of the job with the given job name (so in your case PROCESS_MESSAGE) are running and if it finds more than one, it simply exits without doing anything. If it finds exactly one job (i.e. the one from which it was invoked), then everything is ok and it proceeds with the invocation of the actual program.
So a message like <em>OK, 2 jobs running with a status of "Finished"</em> means that the job ended without actually invoking the underlying program you want to run. So from that perspective it's as if the job never ran...
It's a feature of RSBTONEJOB2 that the job doesn't get canceled and just stops without really doing anything (what you want); for cases where you'd want the job to get canceled you could use RSBTONEJOB. However, this is in your case not required, since overlapping jobs are anyhow recognized, but those two programs were designed for cases where overlapping jobs wreaked havoc, because this scenario was not recognized.
if there are 5 Process_Message jobs that got triggered and try to run, will RSBTONEJOB2 keep one job running while the other 4 will stop running (but will not have a status of cancelled)?
Correct as long as the first job that got invoked is still running when the remaining 4 jobs get triggered.
‎2010 Apr 19 10:55 PM
Hi Harald,
This is how I have set up the job. I only have 1 step which is
No. Program name/command Prog. type Spool list Parameters User Lang.
1 RSBTONEJOB2 ABAP NEW_MESSAGE TESS EN
‎2010 Apr 19 11:02 PM
Hi Harald,
This is how I set up the job. There is only 1 step.
Job Name: PPPI_AUTO_SEND_MESSAGE_EVENT
Step
1 RSBTONEJOB2 ABAP NEW_MESSAGE TESS EN
The Variant is NEW_MESSAGE which has the following value
JOB NAME: PPPI_AUTO_SEND_MESSAGE_EVENT
REPORT: RCOCB002
VARIANT:
Start Condition:
job Start
After Event: SAP_NEW_PROCESS_MESSAGES
As mentioned, i stil get some job cancellation even thought it was able to detect 1 job only. here is a sample of the Job lob.
Date Time Message text Message class Message no. Message
04/19/2010 11:50:29 Job started 00 516 S
04/19/2010 11:50:29 Step 001 started (program RSBTONEJOB2, variant NEW_MESSAGE, user ID TESS) 00 550 S
04/19/2010 11:50:29 Check number of active jobs with name PPPI_AUTO_SEND_MESSAGES_ON_EVENT 00 398 I
04/19/2010 11:50:29 OK, one job running 00 398 S
04/19/2010 11:50:29 *Preceding job not yet completed (plant ) * CB 019 A
04/19/2010 11:50:29 Job cancelled 00 518 A
If you look at this log, it was able to see that there is only 1 job running and yet job got cancelled with an error message of "Preceding job not yet complete (plant).
Any idea?
Thanks
Shirley
‎2010 Apr 20 9:21 AM
I took a quick look at the programs, maybe you should also involve the functional folks. Essentially RCOCB002 is just a wrapper for starting RCOCB003 (triggered via a CALL TRANSACTION of transaction CO51). There is a plant specific version RCOCB004, which allows you to switch off the locking (expand parameters after entering plant via <Shift>+<F7> and then mark radio button <em>No Lock, parallel jobs allowed</em>). Not sure if that is an option, but I think you should investigate this.
If this is not an option and you want to continue usage of RCOCB002, I see two options (based on the puzzling fact that the RSBTONEJOB2 doesn't seem to work):
<ul style="list-style:square">
<li>The program RCOCB003 basically ensures that only one instance is running by using lock object ECOCB_RCOCB003; it would be possible to create your own program to check status of this lock object.</li>
<li>OSS note [200037 - Performance when sending process messages|https://service.sap.com/sap/support/notes/200037] describes a modification (186845), which basically removes the error message from RCOCB003, if another job instance is running already and just exits quietly.</li>
</ul>
In the end though I think you should really have a talk with the functional folks. Furthermore I recommend taking a look at those programs in your system. When I looked briefly in a test system (ECC 6.0) I didn't quite understand why the RSBTONEJOB2 solution didn't work (looking at the way SAP sets the locks to ensure only one running instance). Looking at your test jobs and the programs I'd expect though that you should be able to figure out what the problem is.
Cheers, harald
‎2010 Apr 20 5:40 PM
Thanks Harald for spending time helping me out. I truly appreciate it.
The RSTBONEJOB2 was set up exactly how you have stated but has not changed anything so I am also unsure what the problem is.
I was looking at the note 200037. We are on ECC 6.0 and it seems this note is part of that release. This structure RCOCB003_LOCK_KEY already exist in 6.0 and the
It also has a note:
"This solution leads to the logging of the job with status 'cancelled'. The job failed due to the lock."
The above statement is our issue because it cancels the job and not exiting quitely
Cheers
Shirley
‎2010 Apr 20 7:55 PM
We are on ECC 6.0 and it seems this note is part of that release.
Well, for sure not the modification [186845|https://websmp130.sap-ag.de/sap/bc/bsp/spn/corr_instr/correction_instructions.htm?_EVENT=CORR_OBLI&_CINSTA=0120061532&_CALEID=0000186845&_CPAKID=1] that I had referenced (otherwise you wouldn't see this problem at all).
I personally wouldn't use a modification though, because the involved programs are so simple. Unfortunately the simplicity and lack of modularization also means that it's impossible to define an <em>implicit enhancement</em> point. However, for an ABAPer it would be a trivial task to create a custom version of RCOCB002, which also checks on lock object ECOCB_RCOCB003 before calling transaction CO51. There you could implement whatever you want, i.e. exit with a message indicating that another job instance is already running, waiting until the other job finishes, etc.