Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Checking for a Screen Connection in Background - Without using SY-BATCH

Former Member
0 Kudos
271

Hi

I have a requirement to resolve/patch a particularly dumb development, namely calling a pop-up box in a BADi.

Standard SAP creates an IDOC to post an MM invoice, and whilst the IDOC is created in status 64, the process terminates and creates a short dump. Surprisingly though in this process SY-BATCH is initial.

Basically, I have a pop-up box called via POPUP_TO_CONFIRM that obviously short dumps in background, and I need to prevent this. I don't think the short dump is catchable.

How can I check for a screen connection without using SY-BATCH?

Thanks

Chris

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
128

Try using function module GUI_IS_AVAILABLE. This will tell you if a GUI connection exists.

Regards,

Rich Heilman

4 REPLIES 4

raymond_giuseppi
Active Contributor
0 Kudos
128

You must check

- Not in batch [SY-BATCH|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=sy-batch&adv=false&sortby=cm_rnd_rankvalue] IS INITIAL

- Not in update task (FM [TH_IN_UPDATE_TASK|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=th_in_update_task&adv=false&sortby=cm_rnd_rankvalue])

You may also use FM [RFC_IS_GUI_ON.|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=rfc_is_gui_on.&adv=false&sortby=cm_rnd_rankvalue]

Regards

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
129

Try using function module GUI_IS_AVAILABLE. This will tell you if a GUI connection exists.

Regards,

Rich Heilman

0 Kudos
128

And of course don't ever think to use a

CALL 'RFCControl' ID 'CODE' FIELD '?'.

Regards

Former Member
0 Kudos
128

found this code in

CL_MMIM_DEBUG_CONTROL -> ACKGROUND_PROCESS


    ************************************************************************
    * Find out whether a process runs in background
    ************************************************************************
    METHOD background_process.
    * Include with constants
      INCLUDE tskhincl.
      DATA:
        l_state      TYPE sm04dic-counter,
        l_State_x    like th_bitvalue4,
        l_task_x     like th_bitvalue4.
    * Get task state
      CALL FUNCTION 'TH_USER_INFO'
        IMPORTING
      task_state = l_state.
* Convert to X-fields to make O-compare possible.
  l_State_x = l_state.
* I check for bit TASK_ONLINE.
* It is set if the current process has access to a GUI.
  l_task_x  = task_online.
  IF l_State_x O l_task_x.
    r_background = space.
  ELSE.
    r_background = 'X'.
  ENDIF.
ENDMETHOD.