Werner please help us - Real time job Exception Handling

Hi all,

we have a real time job which process IDOCs from SAP.
We are able to process everything fine.
We have got issue in exception handling. Not able to use try/Catch block inside a real time job. if i use try catch before Rt_ptocess and Rt_End then it is giving application error.
If i put try block after Rt_Begin and before my DF then i am getting error

[Real-time Job:RTJOB_R2P_Price_Book_INFREC]
Try1439 can’t be the first step in real-time processing block. Must have XML or IDoc request. (BODI-1111233)

i have only one DF with simple mapping … as it will always insert the data into Target table.

Now i want to catch all the exceptions and i want to e-mail the status Succsee/Fail to the user.
i have searched so many posts. but couldnt find any solution.

Please help me in this.


samatha.mallarapu (BOB member since 2009-06-16)

Hi All,

We need to catch error in real time job and send mail notification to different groups according to the error. In batch jobs we have implemented it but getting error while trying to implement in real time jobs.

Please help us out.

Thanks in advance

ritesh_kumar (BOB member since 2007-12-05)

That’s a tough one.

First, keep in mind a realtime job is one that runs forever. So actually, anything you put behind the dataflow will never execute!
Second, we have to decide what kind of error we want to capture, one that lets the dataflow continue or one where the dataflow will die.

For the first part, the solution is simple, inside the query you add your smtp_mailto() function somewhere.

But if the dataflow dies because it is an unrecoverable error I wonder what will happen. I would try adding a script right behind the dataflow where you do your emailing (for a test I would simply print() a message into the trace log). I expect you are right, without a try/catch the dataflow will die and terminate the job right away before running the script. But I am not 100% sure because of these realtime brackets. Possible we execute everything behind the bracket in such a case. If we do, we need to check what does happen when you shutdown the realtime service correctly.

Sorry, I have no answer for you just things to try. At the end you might end up with parsing the error log files constantly.

Werner Daehn :de: (BOB member since 2004-12-17)

if you are not doing muchin RT DF and not interested in the response, then you can actaully take in the input message in RT DF and save to Disk and invoke a batch job that reads the XML file and processes it, you can put you error handling logic in this batch job

return the job execution status (job started successfully or failed etc to the caller) and let the batch job do the processing

you can use the exported command to start the batch job without wait, or use webservices to do that

in short use RT job only as event to start the batch job which will actually do the processing

if you are interested in the output then it gets complicated since the RTDF has to wait for the job to complete, and will require some erro handlnig well

manoj_d (BOB member since 2009-01-02)

Thanks Werner and Manoj for your precious suggestion.
Actually in RT DF we are taking IDOC Message as a source and inserting and updating different target tables. Whole processing( Reading from IDOC and target table population) is done in this DF only.

If we use RT DF to populate input message and save it in to disk and use it in another batch job then it would be combination of RT and batch job. We will be able to catch error in batch job but if any error occurs while processing IDOC message in RT DF then how can we catch it.

Manoj can we follow bellow approach in same RT job instead of using batch job.

The first dataflow (call it RT DF1) following RT_Process_Begins reads the IDOC message, unnest it and writes the data to a STG table. DF2 reads the STG table, processes the data and populate target database tables. Place a Try object between RT DF1 and DF2. Place the Catch object after DF2. The source messages are outside of the Try/Catch block.

In above approach also we can’t catch error if happened in RT DF. We can say that we can’t catch error in RT DF.

Ritesh Kumar

ritesh_kumar (BOB member since 2007-12-05)


We got the solution for this. We need to use a script in between TRY and RT_Begin and RT_Process_End and Catch. Then it is working fine. Attached the screen shot as well.
Ream time Exception Handling.PNG

samatha.mallarapu (BOB member since 2009-06-16)


i have the same problem: Try-Catch is not working in RealTime Jobs.
I created a small test-job which raise an unique constraint exception from oracle.

When running the job in normal mode (or published and called via soapUI), the catch block is not performed (tested via outputs and print() in a script) BUT the output-xml is written.
When running in debug mode, the catch block IS performed.

When publishing the job and call it, we have the following behaviour:
1st WS-call returns correct response.
2nd (and following) WS-call(s) returning “Web Services is unable to process the request to call real-time service ‘Test_SPX’ using Access Server ‘ouraccessserver:usedport’. Error: Server sent back error: Communication Error. See real time job log for details.”

The solution with try-catch outside the brackets don’t work for me (always getting an “ApplicationError”).

With the first call, this Webservice get killed.
So I can NEVER be sure if my Webservices are up and running (ok…i can create a batchjob parsing the log files of this webservice but this is not a solution).

Why this is a bug:

  1. catch just don’t work
  2. I can kill a WebService with one soap-Request (talking about “Denial of Service”)
  3. You don’t see all later requests in log at all as RT-job is dead and does no logging at all anymore.
    With this behavior, it’s almost impossible to provide a high-availability (24/7) webservice

Best solution (from my perspective): RealTime-Job Brackets working like try-catch so even if there’s an exception raised by one request, the job just restarts and the following ones are performed correctly.
This would also reflect the idea of webservices as they are “stateless” from a technical point of view.

Feel free to contact me, we can also discuss this topic directly.

@manoj: can you please check this if it’s already posted as Bug (and this is a major one!) as service.sap.com is unavailable at the moment.
If not, I will do so.

@all: anyone maybe has an idea or some similar problems?

Thanks in advance and Best Regards

schaphi :de: (BOB member since 2012-06-04)

I will have to try this out, in any case if try-catch is not supported in a RT Job then I would expct an validation error during Designer time stopping user from adding a try-catch block instead of crashing at run time

if a RT job fails, a new one will be started and if you have multiple instances the other requests will be re-directed to it till the new service instance starts

let me know the case#

manoj_d (BOB member since 2009-01-02)

Hi manoj,

it’s possible to add a try-catch block in a RT-Job and it’s working in Debug-Mode.
I have to run my RT-Jobs just in a single instance as the sequence of processing is important.
When this RT-Job dies because of an exception, the second and all further calls will get an “Webserver not available…”.
Attached an archive with everything you need to retry this on your own.

I also created a SAP-Ticket for this: 162693-2013.

Thanks in advance and Best Regards
RealTime Job Exception Handling.zip (75.0 KB)

schaphi :de: (BOB member since 2012-06-04)

Can we start one level higher? You have a Realtime Service in DS, it does not have any try/catch. What is the behavior and what should it be?

A try/catch in a RT Job is similar to asking having a try/catch within a row of a dataflow. You can’t do that but there are other means of dealing with row errors.

Werner Daehn :de: (BOB member since 2004-12-17)

Hello Werner,

in a RealTime-Job, there’s no difference if you’re using a try-catch or not (at least for the provided test-job):
The first call returns the XML response, the second and all following requests failing.
After some time (around 2-3 minutes - didn’t checked it in detail) the webservice restarts automatically and new requests will work again (until next exception is thrown).

Feel free to contact me directly if you think about a more direct discussion about it (contact details in SAP-Call 162693-2013).

Thanks in advance.

schaphi :de: (BOB member since 2012-06-04)

As said, forget about try/catch. What is it what you want, what is it what you get. Then we talk about how to implement that, if possible.

Werner Daehn :de: (BOB member since 2004-12-17)

Good Morning Werner,

I will have a call today with Manoj about this topic; let’s see what we can figure out.
What I (and I think a lot of other developer too) would like to have as feature:

“Never”-Dieing Jobs
I know “never” is almost not possible. But at least to have all the exceptions which are thrown while running a Webservice-Request have to result in a proper finishing of the job.
Maybe easiest way would be to send a soap exception as result in this case?
This would prevent the job from restarting/being not available.

When exceptions are thrown, there’s normally a technical cause for it: a source or target is not available, some bad implementation, …
In all cases an Admin should check them.
So how to get know there was an exception:

  1. By customer as he claims why his request failed -> “Monitoring by Customer” is not a solution, just a proof you’re interpreting “service” in a wrong way :wink:
  2. Writing a BatchJob or some other Task to check the logfiles of the RealTime-Services.
    Well…that’s an option but not really a good one as logfiles are increasing so with each run we have to check more data.
    And when SAP changes log format with some upgrade, we would have to enhance this too.

So one idea covering both things (and one more):
Enhance the possibilities of the “RealTime-brackets”.
In the “begin”-bracket, offer an option to change the logic of implementation of “job_run_id()” so it will not return the id of the running process (as it’s the same for all webservice-requests) but returning an ID unique for each request.
Maybe also just provide a second function doing exactly the same (so usage in BatchJob would result in returning same value for both functions).
In the "end-"bracket, as “fast solution”, add the possibility to set up a list of e-mail addresses which will get an email when some exception is thrown.
As “best solution”, usage of scripts and dataflows (like in actual catch) for implementing our own handling would be nice.
And if there would be an exception again, just send back a soap exception message in response.

Maybe also thinking about an option in Job-Settings, if a soap exception or some predefined xml (matching the response xsd and not only using fixed static values but maybe also adding the possibility to use values based on functions (e.g. job_name() or the one mentioned above) or variables)) should be returned in case of exception.

Thanks in advance and Best Regards

schaphi :de: (BOB member since 2012-06-04)

I have a real-time job for that I need to send a mail if the job got failed , I have used Try catch blocks in the Job and I was successful in sending the mail on failure. But the client interface for the real-time service got failed on job completion and I need to start it manually after each failure. Could you please help me on this, So that I can avoid failing of client interface.

MEASGARA (BOB member since 2017-09-12)