cancel
Showing results for 
Search instead for 
Did you mean: 

begin-of-transaction in ABAP Objects

Former Member
0 Kudos
293

Hi,

I have a question regarding the (implicit or explicit) begin of a transaction (read: SAP LUW) in ABAP Objects. In this piece of code

 ...
CREATE OBJECT mapping.
TRY.
  mapping->delete_all_embraced_mappings( ).
  mapping->merge_with_begda_overlap( ).
  mapping->merge_with_endda_overlap( ).
  mapping->store( ).
  COMMIT WORK.
CATCH /my/mapping_exception.
  ROLLBACK WORK.
ENDTRY.  

I need a all-or-nohting logic, i.e. I'd like all the methods <i>delete..(), merge..()</i> and <i>store()</i> to run in a single transaction. If any of the methods throws a <i>/my/mapping_exception</i> I want all DB changes (carried out in the methods) rolled back.

Now, how can a mark the <b>begin-of-transaction</b> (the counterpart of the commit work)? I couldn't find information about this in the docu or in the SDN. To prevent misunderstandings: I am building a web application with ABAP Objects, so no dialog steps, PBO-PAIs, function modules, performs etc. are involved!

Regards,

Sebastian Kamp

Accepted Solutions (0)

Answers (1)

Answers (1)

Peter_Inotai
Active Contributor
0 Kudos

Hi Sebastien,

You can use 'CLEANUP' within TRY-ENTRY for rollback. For details check /people/thomas.weiss/blog/2005/04/13/the-new-class-based-exception-handling-in-abap--part-3 .

Then you can build all-or-nothing logic.

Regards,

Peter

Former Member
0 Kudos

Hi Peter,

thanks for your reply. I am afraid, it doesn't really answer my question though.

I am looking for the counterpart of the COMMIT/ROLLBACK WORK commands, i.e. an explicit begin-of-transaction or something like that. How can I state that at some point in my program logic I'd like a transaction (SAP LUW) to <b>start</b>?!

In the code snipplet of my original posting I'd like to put some sort of b-o-t before the

mapping->delete_all_embraced_mappings() method in order to have all DB changes carried out in the methods delete..() until store() to be executed in one transaction.

Regards,

Sebastian

Former Member
0 Kudos

Maybe by using

SET UPDATE TASK LOCAL

.

I think this command acts as a BeginOfTransaction command, it especifies that, till the next CommitWork, all the process has to be done as part of a Transaction.

You could try something like this:


  ...
  TRY
      SET UPDATE TASK LOCAL
      <YOUR_PROCESS_HERE>
      COMMIT WORK
   CATCH
     ....
   ENDTRY
   ...

Hope it helps.

Former Member
0 Kudos

Hola Jorge,

I think this command only works together with CALL FUNCTION.. IN UPDATE TASK and gurantees that all the DB changes occure in the same workprocess as the caller's - not in a dedicated workprocess - thus syncronizing the program flow with the DB changes at the point COMMIT WORK is called.

That is, first the DB changes are carried out then the program proceeds (as opposed to a asyncronos/parallel execution).

Anyway, I am afraid the SET UPDATE TASK LOCAL does not help in our context here.

Regards,

Sebastian

Former Member
0 Kudos

Hi Sebastian,

I have a similar dilemma currently. I would like to define my own LUW in a method of a Class wherein I have multiple DB updates.

I want to rollback all updates in case of error.

My specific issue is that one of the FMs I am using in one such intermittent update does an auto-commit which terminates the LUW abruptly.

Hence I want to enforce a LUW (despite the intermittent commit). I believe this would have been possible with a PERFORM....ON COMMIT. However, since I am using ABAP objects, this approach does not work for me.

Could you please let me know the approach that you followed towards this?

Thanks,

Puja

Sandra_Rossi
Active Contributor
0 Kudos

I wonder if you'll get an answer from Sebastian who didn't post since 6 years, or from the SDN community of more than 1 million people currently. So please post a new question (with a link to that post).

Former Member
0 Kudos

Thanks Sandra,

I feared spawning a new post with the same topic as I believed it to be against the posting rules. Thanks for the clarification. I shall create a new thread.

Regards,

Puja

Former Member
0 Kudos

Hi Sebastian,

I am building a web application with ABAP Objects

If it is using BSP, i guess you can choose it to be a stateless/stateful per your requirement.

http://help.sap.com/saphelp_nw04/helpdata/en/cc/d6eef628f711d5991f00508b6b8b11/content.htm

Regards,

Chen