You could also look for the BAPI FM in the stack (not valid when in update task of course, but there it is always too late), the code could look like :
CALL FUNCTION 'SYSTEM_CALLSTACK' IMPORTING et_callstack = lt_callstack. LOOP AT lt_callstack TRANSPORTING NO FIELDS WHERE eventname CS 'BAPI'. EXIT. ENDLOOP. IF sy-subrc NE 0 " Not a BAPI AND sy-batch IS INITIAL " Not a background job AND sy-binpt IS INITIAL. " Not a batch input
Regards,
Raymond