If your program is running in a background, you can detect this by checking the system variable SY-BATCH. But if you want more information, there are some functions that are useful when working with background jobs:
GET_JOB_RUNTIME_INFO – FM to request the parameters of current job (if your program is running currently in background)
BP_FIND_JOBS_WITH_PROGRAM
SHOW_JOBSTATE
BP_JOBLOG_READ
And as always, you can work with the database tables directly. Two of them, TBTCO (job headers) and TBTCP (job steps) are a good starting point.

