Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 10548

Re: How can I selectively rollback while committing in mass using ABAP Objects?

$
0
0

Hello Brandon,

 

You could use the ABAP transaction service for your requirement. Using the transaction service, you could create a sub transaction for every ,say 15 transactions,of which you could selectively decided to commit only 13 and roll back 2 etc.

 

In your scenario, a transaction consists of 2 BAPI calls, a failure in one of them should stop that transaction, but however, you want to bundle the successful ones and perform a single commit.

 

Here is a code snippet on how to achieve it.

 

TYPE-POOLS  : oscon.

  DATA :      lr_tr_mgr        TYPE REF TO if_os_transaction_manager,
                   lr_trans           TYPE REF TO if_os_transaction,
                   l_error            TYPE char1,
              lr_trans_sub        TYPE REF TO if_os_transaction.

 

*INITIALIZATION.
  cl_os_system=>init_and_set_modes( i_external_commit = oscon_false " No Explicit Commit work, End method triggers it.
                                    i_update_mode     = oscon_dmode_update_task_sync )." COMMIT WORK AND WAIT

START-OF-SELECTION.
  lr_tr_mgr = cl_os_system=>get_transaction_manager( ).

  TRY.
*Parent transaction.
      lr_trans = lr_tr_mgr->create_transaction( ).
      lr_trans->start( ).


DO 15 TIMES.
*Sub transaction
        lr_trans_sub = lr_tr_mgr->create_transaction( ).
        lr_trans_sub->start( ).

*Call your BAPI's.

        "CALL funcion 'xxx'.
*check for return values from the function call for errors.l_error = 'X'.

"call function 'xxx'

*check for return values from the function call for errors.l_error = 'X'.

 

*End of sub transaction.
        IF l_error IS NOT INITIAL."L_ERROR is set when there is a failure message from the bapi calls.
          lr_trans_sub->undo( ).

*End of sub transaction.
        ELSE.
          lr_trans_sub->end( )." This does not commit.Commit happens only when the parent gets committed.
        ENDIF.
ENDDO.
*End of Parent transaction.
      lr_trans->end( ).

    CATCH cx_os_transaction .

*Error handling...

      WRITE: 'Error Occured in transaction processing'.
  ENDTRY.


Viewing all articles
Browse latest Browse all 10548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>