I have a requirement in an existing production development to log errors. It needs to be done in multiple applications.
I created a table and called it in a method. I am calling a Function Module as starting new task to commit work.
This is done to avoid commit work in the actual application. However, in a test program I created I noticed that the system automatically calls commit work instantly when this FM is called.
In the code below, I expect 'Function Module' to be committed in the table, but it commits both 'Prog' and 'Function Module'. 'Prog' is committed instantly when the FM is called and 'Function Module' after commit work in the FM.
What other alternatives do I have? I have tried in update, background task, submit program, perform on commit. Nothing worked.
Main program:
REPORT zak_test_luw.
DATA: ls_log TYPE zdt_error_log,
lv_tms TYPE timestampl.
GET TIME STAMP FIELD lv_tms.
ls_log-time_stamp = lv_tms.
ls_log-msg1 = 'prog'.
ls_log-msg2 = ''.
MOVE-CORRESPONDING sy TO ls_log.
MODIFY zdt_error_log FROM ls_log.
zdcl_utility_new=>update_logging_table( iv_msg1 = |Function Module| ).
Method:
METHOD update_logging_table.
DATA: ls_log TYPE zdt_error_log,
lv_tms TYPE timestampl.
GET TIME STAMP FIELD lv_tms.
ls_log-time_stamp = lv_tms.
ls_log-msg1 = iv_msg1.
ls_log-msg2 = iv_msg2.
MOVE-CORRESPONDING sy TO ls_log.
IF commit_work = abap_true.
MODIFY zdt_error_log FROM ls_log.
COMMIT WORK.
ELSE.
CALL FUNCTION 'ZDF_UPDATE_ERROR_LOG_TBL' STARTING NEW TASK 'LOGTABLE '
EXPORTING
is_log = ls_log.
ENDIF.
ENDMETHOD.
Function module:
FUNCTION zdf_update_error_log_tbl.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IS_LOG) TYPE ZDT_ERROR_LOG
*"----------------------------------------------------------------------
MODIFY zdt_error_log FROM is_log.
COMMIT WORK.
ENDFUNCTION.
SCARR) as per the Help Center, and I'd then love to answer it ;-)