Wednesday, April 23, 2014

Code useful for executing ALV Grid report in Background mode causing short dump

Whenever an ALV grid control program is executed in background, a short dump occurs
Error:   GUI cannot be reached 
Whenever an ALV grid control program is executed in foreground it tries to create some front-end related objects. But when the same program is executed in background, the above error occurs as it fails to create front-end objects (GUI objects). So in order to rectify this problem, we need to use the docking container instead of custom container.
The docking container doesn't need any of the custom controls on the screen, instead it attaches an area to any or all of the four edges of the screen (top, left, right or bottom).
The behavior of the areas in the container is determined by the sequence in which they are initialized. Docking Containers are attached to the screen from the inside out. This means that when you create a second container, it is attached to the edge of the screen, and the container that was already there is pushed outwards.
We can use the below code when ALV is used in background programs
DATA : or_doc TYPE REF TO cl_gui_docking_container.
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
 CREATE OBJECT or_custom_container
    container_name = c_container.
    i_parent = or_custom_container.
    i_parent = or_doc.
We can also use  SAP system variable SY-BATCH  is ‘X’ to check if the program is being executed in background or foreground