Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Transaction service for persistent class: No COMMIT performed

Former Member
0 Kudos

Hi there,

I have a Z table and a corresponding persistence class.

When I try to create a table record, it doesn't create the table entry.

This is a small test report:


REPORT ztest.

DATA:
     r_transaction_mgr     TYPE REF TO if_os_transaction_manager,
     r_transaction         TYPE REF TO if_os_transaction,
     r_if_request_agent    TYPE REF TO zca_if_requests,
     r_if_request          TYPE REF TO zcl_if_requests.

START-OF-SELECTION.

r_transaction_mgr = cl_os_system=>get_transaction_manager( ).
r_transaction = r_transaction_mgr->create_transaction( ).

TRY.
     r_transaction->start( ).

     r_if_request_agent = zca_if_requests=>agent.

*    Create persistent object for ZFI_REQUESTS
     r_if_request =
       r_if_request_agent->create_persistent(
         i_module_name    = 'FI/CO'
         i_interface_name = 'ORDER_INVOICES'
         i_udate          = sy-datum
         i_utime          = sy-uzeit
       ).
  
     r_if_request->set_processed( 1 ).
     r_if_request->set_not_processed( 1 ).

     r_transaction->end( ).

   CATCH cx_os_error.

     r_transaction->undo( ).

ENDTRY.

It only works if I do a COMMIT WORK instead of r_transaction->end( ).

What can be the reason for that?


I've also tried to put


LOAD-OF-PROGRAM.
* set the transaction mode
   cl_os_system=>init_and_set_modes(
       i_external_commit = oscon_false
       i_update_mode     = oscon_dmode_direct
   ).

But then I get a short-dump (exception CX_OS_SYSTEM, ID SYSTEM_NOT_INITIAL).

Best regards,

Thorsten.

5 REPLIES 5

Former Member
0 Kudos

Thorsten,

Since you are using transaction manager, commit should not be required. This is notified to the system by calling the class/method cl_os_system=>init_and_set_modes(i_external_commit = oscon_false) as you are doing.

The dump happens when the system is not initial or is running in Update task.

Debug the method cl_os_system=>init_and_set_modes and make sure you do not get the dump (the else part of the code issues a dump) and then check if r_transaction->end( ) adds the record to the DB. If yes, you know what the problem is.


In order to set the system to its initial state, try calling the method INIT within CL_OS_SYSTEM.

Thanks,

Vikram.M

0 Kudos

Hi Vikram,

the problem is that INIT_STATE in method cl_os_system=>init_and_set_modes( ) is equal to 2.

But I don't know why.

How can I achieve to set INIT_STATE to 0 before calling the method?


Could it be that some settings need to be changed in order to use transaction services properly?


Best regards,

Thorsten.

0 Kudos

Hi again,

if I do this at the LOAD-OF-PROGRAM section it works!


LOAD-OF-PROGRAM.
* set the transaction mode
   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_direct
     ).
   ENDIF.

Strange, isn't it?

What effect does the IF cl_os_system=>init_state IS INITIAL. have?


Best regards,

Thorsten.

0 Kudos

Thorsten,

why don't you add a break point in the IF statement and see the # of times the its gets executed. I suspect the dump was because the same method was called more than once. The first time, the system would have been set to initial state and the second time when it gets called it should have dumped.

Thanks,

Vikram.M

0 Kudos

If we look into he code inside Method

if ( INIT_STATE is initial ).

     EXTERNAL_COMMIT     = I_EXTERNAL_COMMIT.

     INITIAL_UPDATE_MODE = I_UPDATE_MODE.

     call function 'TH_IN_UPDATE_TASK'

       importing

         IN_UPDATE_TASK = TMP_UPDATE_TASK.

     if ( TMP_UPDATE_TASK = 1 ).

       UPDATE_TASK = OSCON_TRUE.

     else. "( It's no update task )

       UPDATE_TASK = OSCON_FALSE.

     endif.

     if ( ( UPDATE_TASK  = OSCON_TRUE  ) and

          ( EXTERNAL_COMMIT = OSCON_FALSE ) ).

       raise exception type CX_OS_SYSTEM

         exporting

           TEXTID = CX_OS_SYSTEM=>COMPATIBILITY_MODE_ONLY.

     endif.

     call method INIT.  "Here INIT_STATE is set to 1.

   else.

     raise exception type CX_OS_SYSTEM

       exporting

         TEXTID = CX_OS_SYSTEM=>SYSTEM_NOT_INITIAL.

   endif.


So the method only runs when INIT_STATE is initial. Else exception is raised and since you are not catching that in your program you are getting the dump.

The way the coding is done the method INIT_AND_SET_MODES can only be called once in a transaction state(Sort of Singleton concept) and provided Method INIT is not called before.


R