Here’s a piece of code that you can use in your program to check active background job.
DATA: lt_joblist LIKE tbtcjob OCCURS 0 WITH HEADER LINE, ld_line TYPE i. CALL FUNCTION 'BP_FIND_JOBS_WITH_PROGRAM' EXPORTING abap_program_name = sy-repid abap_variant_name = sy-slset dialog = 'N' status = 'R' TABLES joblist = lt_joblist EXCEPTIONS no_jobs_found = 1 program_specification_missing = 2 invalid_dialog_type = 3 job_find_canceled = 4 OTHERS = 5. IF lt_joblist IS NOT INITIAL. DESCRIBE TABLE lt_joblist LINES ld_line. IF ld_line > 1. Message i000(zz) with 'Backgound Job is still active'. ENDIF. ENDIF.