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: 

cl_gui_alv_grid in background

Former Member
0 Kudos

Hi,

How to run ALV report in Background which is created using cl_gui_alv_grid. I am getting error ,

Control Framework: Fatal error - GUI cannot be reached

Regards,

Balavardhan

1 ACCEPTED SOLUTION

Former Member

Hello -

You can use this in background. All you need is to add this piece of code:

IF  gv_alv_cont1 IS INITIAL.

    CALL METHOD cl_gui_alv_grid=>offline
      RECEIVING
        e_offline = gv_offline.

    IF gv_offline IS INITIAL.

*  Create object for ALV.
      CREATE OBJECT gv_alv_cont1
            EXPORTING
              container_name = gc_cc_alv1.

    ENDIF.

    CREATE OBJECT gv_alv_grid1
        EXPORTING i_parent = gv_alv_cont1.

*  Display ALV grid
    CALL METHOD gv_alv_grid1->set_table_for_first_display
      EXPORTING
        is_variant                    = gwa_variant
        i_save                        = gc_a
        is_layout                     = gwa_layout
        it_toolbar_excluding          = lt_exclude
      CHANGING
        it_outtab                     = gt_data
        it_fieldcatalog               = gt_fieldcat
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.

This will work in background.

Thanks,

Vijay

8 REPLIES 8

Former Member
0 Kudos

Anything which is GUI dependent will not work in background.

0 Kudos

>

> Anything which is GUI dependent will not work in background.

Hello,

There you are mistaken my friend we have a workaround for this

@OP: You can get details in this [link|;.

P.S->BETTER to use REUSE_ALV_GRID_DISPLAY as it can in foreground or background. If we use OO ALV controls, we won't be able to run the program in background.

FYI, REUSE_ALV_GRID_DISPLAY is also converted to list when executed in background. Difference is that for REUSE_ALV_GRID_DISPLAY we donot have to code for it but if we use CL_GUI_ALV_GRID, we have to explicitly handle the situation.

Hope i am clear.

Suhas

0 Kudos

Hi Suhas,

I too know that.. :). Just giving the information that OO ALV(CL_GUI_ALV_GRID) won't work in background where as REUSE_ALV_GRID_DISPLAY works. anyways thanks.

Regards,

Nagaraj

0 Kudos

Hello Nagaraj,

I presume OO ALV will work in background, if we use the code i have shown above.

Thanks,

0 Kudos

Thanks for letting me know that there a few exceptions to my statement. I should have searched before posting.

0 Kudos

Hi,

Yes you are right whatever code you wrote is correct..But if we don't write that code then the error will come. OO ALV won't work without the code you wrote...

Regards,

Nagaraj

former_member404244
Active Contributor
0 Kudos

hI,

Check the below link.

P.S->BETTER to use REUSE_ALV_GRID_DISPLAY as it can in foreground or background. If we use OO ALV controls, we won't be able to run the program in background.

Regards,

Nagaraj

Former Member

Hello -

You can use this in background. All you need is to add this piece of code:

IF  gv_alv_cont1 IS INITIAL.

    CALL METHOD cl_gui_alv_grid=>offline
      RECEIVING
        e_offline = gv_offline.

    IF gv_offline IS INITIAL.

*  Create object for ALV.
      CREATE OBJECT gv_alv_cont1
            EXPORTING
              container_name = gc_cc_alv1.

    ENDIF.

    CREATE OBJECT gv_alv_grid1
        EXPORTING i_parent = gv_alv_cont1.

*  Display ALV grid
    CALL METHOD gv_alv_grid1->set_table_for_first_display
      EXPORTING
        is_variant                    = gwa_variant
        i_save                        = gc_a
        is_layout                     = gwa_layout
        it_toolbar_excluding          = lt_exclude
      CHANGING
        it_outtab                     = gt_data
        it_fieldcatalog               = gt_fieldcat
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.

This will work in background.

Thanks,

Vijay