Skip to Content

Integration of BOPF Business Objects and Existing Applications (Part 2/2)

In the first part of this article a sequence diagram has been discussed showing the interaction between an existing legacy application and BOPF business objects during the save phase of a common transaction. In addition to this, an implementation example of the legacy application's save sequence is now provided.

Master Transaction Manager - Implementation Example

   " --- 1. execute some application specific logic ---------------

   " ...

   " --- 2. add pre-commit logic for BOPF objects -----------------

   DATA(lo_message_container) = /bobf/cl_frw_factory=>get_message( ).

   " 2.1 set update task local

   " if this can't be set in your scenario, use COMMIT WORK AND WAIT later on to ensure,

   " that the changes done in the transaction are written to the database before the next session continues

   SET UPDATE TASK LOCAL.

   " 2.2 get slave transaction manager

   DATA(lo_slave_manager) = /bobf/cl_tra_trans_mgr_factory=>get_slave_transaction_manager( ).

   " 2.3 FINALIZE phase to prepare BOPF objects to be saved

   lo_slave_manager->finalize(

     IMPORTING

       eo_message          = DATA(lo_finalize_message)

       et_rejecting_bo_key = DATA(et_rejecting_bo_key)

       ev_rejected         = DATA(ev_rejected) ).

   lo_message_container->add( lo_finalize_message ).

   " 2.3.1 AFTER_FAILED_SAVE phase in case that a BO rejects the save

   IF ev_rejected = abap_true.

     " allow BOPF objects to cleanup changes that happend while the failed finalization phase

     lo_slave_manager->after_failed_save(

       IMPORTING

         eo_message = DATA(lo_after_failed_message) ).

     lo_message_container->add( lo_after_failed_message ).

     " as at least one BOPF objects has reject the save, thus the save process must be canceled

     " return messages (depending on the legacy application)

     lo_message_container->get_messages( IMPORTING et_message = DATA(lt_message) ).

     RETURN.

   ENDIF.

   " 2.4 CHECK_BEFORE_SAVE to check the BOPF BOs if they can be saved at all

   lo_slave_manager->check_before_save(

     IMPORTING

       eo_message          = DATA(lo_before_save_message)

       et_rejecting_bo_key = et_rejecting_bo_key

       ev_rejected         = ev_rejected ).

   lo_message_container->add( lo_before_save_message ).

   " 2.4.1 AFTER_FAILED_SAVE:  phase in case that a BO rejects the save

   IF ev_rejected = abap_true.

     " allow BOPF objects to make things undone that happend due to finalization

     lo_slave_manager->after_failed_save(

       IMPORTING

         eo_message = lo_after_failed_message ).

     lo_message_container->add( lo_after_failed_message ).

     " as at least one BOPF objects has reject the save, the save process must be canceled

     " return messages (depending on the legacy application)

     lo_message_container->get_messages( IMPORTING et_message = lt_message ).

     RETURN.

   ENDIF.

   " 2.5 ADJUST_NUMBERS: Invoke BOPF BOs that use late numbering

   lo_slave_manager->adjust_numbers(

       IMPORTING

         eo_change  = DATA(lo_adjust_num_change)

         eo_message = DATA(lo_adjust_num_message) ).

   lo_message_container->add( lo_adjust_num_message ).

   " 2.6 ON_NUMBERS_ADJUSTED: Invoke BOPF BOs that spread the numbers to other locations within the BO

   lo_slave_manager->on_numbers_adjusted(

       EXPORTING

         io_change  = lo_adjust_num_change

       IMPORTING

         eo_message = DATA(lo_adjusted_num_message) ).

   lo_message_container->add( lo_adjusted_num_message ).

   " 2.7 DO_SAVE

   lo_slave_manager->do_save(

     IMPORTING

       et_rejecting_bo_key = DATA(lv_rejecting_bo_key)

       eo_message          = DATA(lo_do_save_message)

       ev_rejected         = ev_rejected ).

   lo_message_container->add( lo_do_save_message ).

   IF ev_rejected = abap_true.

     " Save has been rejected - rollback the transaction and raise a dump

     ROLLBACK WORK.

     " return messages (depending on the legacy application)

     lo_message_container->get_messages( IMPORTING et_message = lt_message ).

     RETURN.

   ENDIF.

   " --- 3. commit work ----------------------------------------------

   " register dummy update task to ensure that all BOPF locks are released

   CALL FUNCTION '/BOBF/TRA_DUMMY_UPDATE_TASK' IN UPDATE TASK.

   COMMIT WORK.

   " --- 4. add post-commit logic for BOPF objects ----------------

   " 4.1 AFTER_SUCCESSFUL_SAVE

   lo_slave_manager->after_successful_save(

      IMPORTING

        eo_message = DATA(lo_after_save_message) ).

   lo_message_container->add( lo_after_save_message ).

   " --- 5. execute some application specific logic

   " ...

   " --- 6. return messages

   " return messages (depending on the legacy application)

   lo_message_container->get_messages( IMPORTING et_message = lt_message ).

   RETURN.

Tags: