Prevent DYNPRO_SEND_IN_BACKGROUND Error in Background Process
ABAP programs throw Dynpro_Send_In_Background error when running in background and popup is displayed using Popup_To_Confirm_Step function module. To prevent exception sy-batch and sy-binpt system fields are frequently controlled. Besides these two system variables, ABAP developers can use GUI_IS_AVAILABLE function module and cl_mmim_debug_control=>background_process method to determine if the current program is running as background process or not.
In this ABAP tutorial, I'll show programmers how to use these three methods to determine if current program is running in background as a background process or not for preventing the runtime error DYNPRO_SEND_IN_BACKGROUND in productive SAP systems.
Use System Fields sy-batch and sy-binpt for Background Process
In ABAP programs, pop up dialog screens are frequently used. Although these dialog screens provide a preffered method to enable SAP users to interact with ABAP programs and provide data, it is a general problem frequently experienced if these ABAP reports are executed in background and as batch input.
Below is a sample ABAP program which displays pop up confirmation screen in front of SAP user running the ABAP program.
And if the background execution is not checked within ABAP codes, following error will be thrown and observed using SAP ST22 transaction for listing ABAP Runtime Errors.
Use System Fields sy-batch and sy-binpt for Background Process
In fact, ABAP programmers can use the ABAP system fields which are always available to test the background execution in an ABAP program.
SY-BATCH user is used in general to check if an ABAP program or task is running in background or not. If sy-batch system variable value is equal to 'X' then the ABAP program is running in background. Otherwise, sy-batch value is space or initial.
An other system variable that can be used to check whether an ABAP program is running in background or not is testing the value of SY-BINPT variable. System variable sy-binpt has value 'X' when the ABAP program is running within an ABAP batch input session.
So one of the easiet easiest method to test background execution of an ABAP program is enclosing the popup function module POPUP_TO_CONFIRM_STEP within following ABAP IF clause. Unfortunately, this method sometimes is not enough to prevent DYNPRO_SEND_IN_BACKGROUND errors in SAP systems.
Use GUI_IS_AVAILABLE Function Module for Background Execution
But my favorite method for preventing DYNPRO_SEND_IN_BACKGROUND errors is using the ABP function module GUI_IS_AVAILABLE and check its return parameter. ABAP function module GUI_IS_AVAILABLE can be used by ABAP programmers to to determine if a SAP GUI is connected and available or not.
If return parameter of GUI_IS_AVAILABLE function module returns 'X' then the current running program is attached to a user interface. On the other hand, if return parameter is equal to space or is initial then this means that running ABAP program is not connected with a GUI and running in the background.
Call cl_mmim_debug_control=>background_process Class Method
Another and more enhanced method to determine whether a task is running in background or not, ABAP developers can use cl_mmim_debug_control class background_process static method.
background_process class method returns r_background parameter which shows whether the calling program is running in background or not.
By controlling the r_background parameter, ABAP programmers can call or skip function module POPUP_TO_CONFIRM_STEP which causes DYNPRO_SEND_IN_BACKGROUND exception when executed in background processes.
I hope especially the second and the third methods will enable ABAP developers who display pop-up screens by calling POPUP_TO_CONFIRM function module from short dumps in background execution.