SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

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.

popup screen using POPUP_TO_CONFIRM_STEP ABAP function module

Below is a sample ABAP program which displays pop up confirmation screen in front of SAP user running the ABAP program.

DATA lv_answer TYPE c.

CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
 EXPORTING
* DEFAULTOPTION = 'Y'
  textline1 = 'Hello Kodyaz!'
* TEXTLINE2 = ' '
  titel = 'POPUP_TO_CONFIRM_STEP Test Program'
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'
 IMPORTING
  answer = lv_answer.
" J, Yes; N, No; A, Cancel
Code

ABAP pop-up function module POPUP_TO_CONFIRM_STEP causing DYNPRO_SEND_IN_BACKGROUND error

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.

SAP DYNPRO_SEND_IN_BACKGROUND error in ST22 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.

IF sy-batch IS INITIAL AND sy-binpt IS INITIAL. " then executed via GUI

ELSE. " running in background

ENDIF.
Code

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.

DATA lv_guiavailable TYPE c.
CALL FUNCTION 'GUI_IS_AVAILABLE'
 IMPORTING
  return = lv_guiavailable.
" X, GUI available, Initial => no GUI

IF lv_guiavailable = 'X'. " attached with GUI

ELSE. " running in background

ENDIF.
Code

GUI_IS_AVAILABLE function module used to prevent DYNPRO_SEND_IN_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.

DATA lv_background TYPE c.
CALL METHOD cl_mmim_debug_control=>background_process
 RECEIVING
  r_background = lv_background.

IF lv_background = 'X'. " being executed as a background task

ENDIF.
Code

background_process method call for preventing DYNPRO_SEND_IN_BACKGROUND error

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.



SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.