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

Re: Mass table updates using Transaction object services(OS)

$
0
0

Hello Suhas,

 

Here is an example below, where I call a BAPI and also update a Z test table ( the table has only field - counter ). The Update module updates 5 records at a time. In the below example, we create a transaction, which invovles calling a BAPI and a sub transaction which updates 5 table entries.

When the Parent transaction is complete, both the BAPI as well as the Table updates are completed. This is just a basic scenario, there could be other complicated scenario's too.

 

I had written a response some time back for selective transaction control.However, I had tried with persistent objects back then.

http://scn.sap.com/thread/3317699

 

Similarly we could create as many dependencies and as many transaction objects as we wish. That's why  I had mentioned that the transaction service is just a "wrapper", which gives a lot of

flexibility.

 

 

Hope this helps . Here is the code snippet.

TYPE-POOLS  : oscon.

DATA : lr_tr_mgr TYPE REF TO if_os_transaction_manager,
       lr_trans  TYPE REF TO if_os_transaction,
       lr_trans_sub  TYPE REF TO if_os_transaction,
       l_tabix   TYPE sy-tabix,
       lt_table TYPE STANDARD TABLE OF ztest_table,
        lr_excpn  TYPE REF TO cx_os_transaction.

 

FIELD-SYMBOLS : <fs_table> TYPE ztest_table.

 

DATA: w_header  TYPE bapi2017_gm_head_01,
      w_code    TYPE bapi2017_gm_code,
      it_item   TYPE TABLE OF bapi2017_gm_item_create,
      wa_item   TYPE bapi2017_gm_item_create,
      it_return TYPE TABLE OF bapiret2,
      wa_return TYPE bapiret2,
      w_head    TYPE bapi2017_gm_head_ret,
      w_matdoc  TYPE bapi2017_gm_head_ret-mat_doc,
      w_matyear TYPE bapi2017_gm_head_ret-doc_year.


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 )." oscon_dmode_update_task_sync -->COMMIT WORK AND WAIT
  "OSCON_DMODE_UPDATE_TASK  - > in update task.

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( ).

      l_tabix = sy-tabix.

*        l_create = 'X'.

      REFRESH  it_item.
      w_code = '03'.

      w_header-pstng_date     = w_header-doc_date = sy-datum.
      w_header-pr_uname       = sy-uname.
      w_header-ver_gr_gi_slip = '3'.

      wa_item-material       = XXXX.
      wa_item-plant          = 'XXXX.
      wa_item-stge_loc       = 'XXXX'.
      wa_item-move_type      = 'XXXX'.
      wa_item-entry_qnt      = '1.00'.
      wa_item-entry_uom      = 'EA'.
      wa_item-costcenter     = 'XXXX'.

 


      wa_item-gr_rcpt        = '1XXXX'..

      APPEND wa_item TO it_item.

      CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
        EXPORTING
          goodsmvt_header  = w_header
          goodsmvt_code    = w_code
        IMPORTING
          goodsmvt_headret = w_head
          materialdocument = w_matdoc
          matdocumentyear  = w_matyear
        TABLES
          goodsmvt_item    = it_item
          return           = it_return.

      lr_trans_sub = lr_tr_mgr->create_transaction( ).
      lr_trans_sub->start( ).

      DO 5 TIMES.
        APPEND INITIAL LINE TO lt_table ASSIGNING <fs_table>.
        <fs_table>-counter = sy-index  + 70. " some random value.
        IF sy-index EQ '5'.
          CALL FUNCTION 'ZTEST_TABLE_UPDATE' IN UPDATE TASK
            TABLES
              it_table = lt_table.
          lr_trans_sub->end( ).
        ENDIF.
      ENDDO.
      lr_trans->end( ).

    CATCH cx_os_transaction INTO lr_excpn .
*Error handling...
      WRITE: 'Error Occured in transaction processing'.
  ENDTRY.

 

Thanks,

Venkat.


Viewing all articles
Browse latest Browse all 10498


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