Hello,
I have a code with comment. I need to use “COMMIT WORK” in ABAP Object Oriented but I know it don’t work just like in Functional Module. I found DEMO_TRANSACTION_SERVICE, but is not enough.
DATA: transaction TYPE REF TO if_os_transaction,
transaction_manager TYPE REF TO if_os_transaction_manager.
IF cl_os_system=>init_state IS INITIAL.
cl_os_system=>init_and_set_modes( i_external_commit = oscon_false
i_update_mode = oscon_dmode_update_task_sync ).
ENDIF.
transaction_manager = cl_os_system=>get_transaction_manager( ).
transaction = transaction_manager->create_transaction( ).
TRY.
transaction->start( ).
“(1)
MODIFI ztable_1 from ls_1.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE zcx_wm_util
EXPORTING
textid = zcx_wm_util=>data_not_saved.
ENDIF.
“(2)
MODIFI ztable_2 from ls_2.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE zcx_wm_util
EXPORTING
textid = zcx_wm_util=>data_not_saved.
ENDIF.
“(3)
CALL FUNCTION ‘BAPI_GOODSMVT_CREATE’ ” DESTINATION ‘NONE’
EXPORTING
goodsmvt_header = ls_goodsmvt_header
goodsmvt_code = iv_movement
IMPORTING
goodsmvt_headret = ls_goodsmvt_headret
TABLES
goodsmvt_item = lt_goodsmvt_item
return = rt_error.
DATA(lv_check_error) = REDUCE i( INIT x = 0 FOR <line> IN rt_error
WHERE ( type = ‘E’ OR type = ‘A’ ) NEXT x = x + 1 ).
IF lv_check_error = 0.
“HERE IS DUMP
” Do I need use TRANSACTION COMMIT?
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = abap_true
IMPORTING
return = rt_error.
ELSE.
RAISE EXCEPTION TYPE zcx_wm_util
EXPORTING
textid = zcx_wm_util=>goodsmvt_not_create.
ENDIF.
WAIT UP TO 2 SECONDS.
CALL FUNCTION ‘L_TO_CREATE_MULTIPLE’
…
IF sy-subrc <> 0.
” Do I need use ROLLBACK?
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’
IMPORTING
return = rt_error.
RAISE EXCEPTION TYPE zcx_wm_util
EXPORTING
textid = zcx_wm_util=>data_not_saved.
ENDIF.
transaction->end( ). “Succes if all is ok
CATCH zcx_wm_util INTO DATA(lx_wm_utill).
” Not so good, needed rollback all changes
transaction->undo( ). ”
clear_screens_data( ).
ENDTRY.
ENDMETHOD.
with comment