The class cl_system_transaction_state contains several useful utility methods:
get_in_update_task: return the flag whether current code is running with normal work process or in update work process
get_on_commit: return flag whether current code is called because of a previous registration via PERFORM ON COMMIT and triggered by COMMIT WORK
get_sap_luw_key: return current LUW ID
I just use a very simple report to test them. First I call the FM ZSQF in a normal way, then call it via update task, then register it with PERFORM ON COMMIT and trigger it via COMMIT WORK.
WRITE: / 'Direct call ZSQF begin...'.
DATA(lv_luw_key) = cl_system_transaction_state=>get_sap_luw_key( ).
WRITE:/ 'LUW key in main program:', lv_luw_key.
CALL FUNCTION 'ZSQF'.
WRITE: / 'Direct call ZSQF end...'.
CALL FUNCTION 'ZSQF' IN UPDATE TASK.
PERFORM call_fm ON COMMIT.
COMMIT WORK AND WAIT.
lv_luw_key = cl_system_transaction_state=>get_sap_luw_key( ).
WRITE:/ 'LUW key in main program after COMMIT WORK:', lv_luw_key.
FORM call_fm.
WRITE:/ 'ZSQF is called on COMMIT begin...'.
CALL FUNCTION 'ZSQF'.
WRITE:/ 'ZSQF is called on COMMIT end...'.
ENDFORM.
DATA(lv_in_update) = cl_system_transaction_state=>get_in_update_task( ).
DATA(lv_on_commit) = cl_system_transaction_state=>get_on_commit( ).
DATA(lv_luw_key) = cl_system_transaction_state=>get_sap_luw_key( ).
WRITE: / 'Am I in update task? ' , lv_in_update.
WRITE: / 'Am I triggered via PERFORM ON COMMIT?', lv_on_commit.
WRITE: / 'Current LUW Key' , lv_luw_key.