At times it may be required to run ALV using class CL_GUI_ALV_GRID in the background mode. ALV grid object reference developed using CL_GUI_ALV_GRID needs a custom screen and custom container as “Parent Object”.
If ALV is scheduled as a background job either from SM36 or from program menu then it generates a short dump.
As a workaround, use below logic while initializing the ALV Grid and Container Object in PBO of custom screen.
1. Necessary data declaration for object reference
CONSTANTS:
c_ccontainer TYPE scrfname VALUE 'CCONTAINER'.
DATA: g_ccontainer TYPE REF TO cl_gui_custom_container,
g_grid TYPE REF TO cl_gui_alv_grid.
2. Code in PBO for Initialization of Object
Check whether user is working in Offline mode using static method CL_GUI_ALV_GRID=>Offline(). If yes then do not initialize container object. If No then initialize both container and ALV grid instance for GUI.
IF g_ccontainer IS INITIAL. IF cl_gui_alv_grid=>offline( ) IS INITIAL. CREATE OBJECT g_ccontainer EXPORTING container_name = c_ccontainer repid = sy-repid dynnr = sy-dynnr EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS = 6. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. CREATE OBJECT g_grid EXPORTING i_parent = g_ccontainer EXCEPTIONS error_cntl_create = 1 error_cntl_init = 2 error_cntl_link = 3 error_dp_create = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ELSE. CREATE OBJECT g_grid EXPORTING i_parent = g_ccontainer EXCEPTIONS error_cntl_create = 1 error_cntl_init = 2 error_cntl_link = 3 error_dp_create = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDIF. ELSE. CALL METHOD g_grid->refresh_table_display EXPORTING i_soft_refresh = c_true. ENDIF.
Once the above changes would be done then the ALV grid would be displayed as ALV List (not as grid) in background mode.
