To check if a program is running in background usually one takes a peek at SY-BATCH. SY-BINPT can also be used to check if the background program is a BDC session. You usually check one of these.
There is a similar but not exactly equal question, though. How do you ask if the GUI is available? Most times both questions will have the same answer. But not always.
It’s like saying the Sun can be seen during the day while the Moon can be seen during the night. If the sky is cloudy you won’t be seeing them.
The answer to this peculiar question can be given by this function module:
CALL FUNCTION 'GUI_IS_AVAILABLE' IMPORTING RETURN = is_gui_available.
You can also use this method (which makes use of GUI_IS_AVAILABLE (and does some more stuff (but I will not waste your time explaining nor mine trying to understand it))):
is_offline = CL_GUI_ALV_GRID=>OFFLINE().
Since this post is about the GUI, I picked the photo of a random celebrity called Guilherme. I felt like a good choice.
Greetings from Abapinho.