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

PERFORM ... ON COMMIT and ROLLBACK

thw
Explorer
0 Likes
4,210

Hello ABAP experts,

I am quite new to SAP LUW, want to execute 2 SQL statements in one unit and didn't find anyhting in the web ...

So to keep it simple I have the following programme.

On COMMIT WORK it first executs form insert1 and then update1.

If sy-subrc <> 0 in from insert1 I want to do a rollback, but I am not allowed to use ROLLBACK WORK statement in that form.

So what possibilities do I have to raise an error without aborting the whole programme and to rollback the work?

Thanks in advance,

Thomas

1 ACCEPTED SOLUTION
Read only

oliver_wurm
Active Participant
2,860

Hi Thomas,

the forms you have passed to the update task are executed in that sequence as your PERFORM Statements. Each form has to check the returncode of the SQL Statements and if there is an error it needs to stop the update Task. So if "insert1" gets SY-SUBRC = 4 it should raise an abort message (Type A) which will automatically perform a rollback work and will stop the LUW immediately.

Regards

Oliver

5 REPLIES 5
Read only

Juwin
Active Contributor
0 Likes
2,860

You should perform all the validations before the COMMIT WORK statement. The INSERT statement will fail only if the key is already existing in the table. That check can be performed well in advance, not waiting for the actual INSERT to happen.

Thanks,

Juwin

Read only

Former Member
0 Likes
2,860

Agree with Juwin.

Not sure what your requirement . Why would you first insert and then update the same table.

Still one way can be to call the subroutine for update inside the subroutine for Insert instead of calling it in ON COMMIT based on the sy-subrc value after insert statement.

If the INSERT has failed there is nothing to ROLLBACK as the data is not inserted in database.

R

Read only

oliver_wurm
Active Participant
2,861

Hi Thomas,

the forms you have passed to the update task are executed in that sequence as your PERFORM Statements. Each form has to check the returncode of the SQL Statements and if there is an error it needs to stop the update Task. So if "insert1" gets SY-SUBRC = 4 it should raise an abort message (Type A) which will automatically perform a rollback work and will stop the LUW immediately.

Regards

Oliver

Read only

Private_Member_7726
Active Contributor
0 Likes
2,860

Hi,

The Error Handling for Bundled Updates - ABAP Programming (BC-ABA), is not very clear, but you could try if 'E' message achieves what you want in dialog. However, when executed in background, the 'E' message would still terminate execution.

As others already pointed out, error in update processing should be treated as "unrecoverable error" or "system error" in SAP - as something worthy of termination. Or in other words, it's not a good idea to try to work around application errors in update processing.

I don't know much about "BDS Barcodes" but as a general rule, it's never a good idea to try to modify SAP standard tables direcly.

cheers

Janis

Read only

thw
Explorer
0 Likes
2,860

Thanks for your replies.

The real programme is more complex than the one above, but it is only a interim solution, so I it's maybe a bit more dirty than usual :

There are three statements on 3 different tables:

  • update on table 1
  • insert in table 2
  • delete in table 3
    => table 1+2 are customer table, table 3 is a sap table, but I couldn't find functions/methods to delete, so I use sql statements.

These statements are one unit.

As this programme is doing a mass processing, I thought that for every unit it is possible to catch an error and write it in a protocol without changing something in that unit ... and then going on with the next unit.

So if an error happens I just use MESSAGE and TYPE 'A'. This is the common way, right?

Thanks,
Thomas