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)
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.