Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

what exception should I use when commit work fails ?

Former Member
0 Likes
1,439

hi all:

I create a class with methods to insert , modify and delete trasaction data,

when commit work fails, I want to throw an exception, what exception should I use

for this case?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,144

If you want to raise an exception every time your commit fails, then you just need to create your own custom exception class and raise it inside your methods every time commit fails.

By the way, in order for you to know if your commit command failed or not- ensure that you add the AND WAIT command so that the sy-subrc field changes for success and error. Otherwise, your COMMIT WORK will always return 0 sy-subrc.

4 REPLIES 4
Read only

Former Member
0 Likes
1,144

Hi,

Two non-catchable exceptions for commit work.

COMMIT_IN_PERFORM_ON_COMMIT

COMMIT_IN_POSTING

Regards and Best wishes.

Read only

0 Likes
1,144

do you throw an exception in a class method if commit work fails, what do you usually do ?

Read only

Former Member
0 Likes
1,145

If you want to raise an exception every time your commit fails, then you just need to create your own custom exception class and raise it inside your methods every time commit fails.

By the way, in order for you to know if your commit command failed or not- ensure that you add the AND WAIT command so that the sy-subrc field changes for success and error. Otherwise, your COMMIT WORK will always return 0 sy-subrc.

Read only

Former Member
0 Likes
1,144

In general, you should do your commit using CALL FUNCTION IN UPDATE TASK. As this runs in a different process, you will never be able to catch an exception in your main task, even if you throw one in the Open SQL code. What you should do is carefully validate your data before posting it to the database, so that commit cannot fail for data integrity reasons. If it fails for technical reasons (DB down etc.) there is nothing that your code could do about it anyway, so in this case even getting an exception would be no use. What exactly is it you are trying to accomplish?

-- Sebastian