abapalvdynprosap-selection-screens

Manage layouts in ALV grid does not work in splitter container


I try to use an ALV grid inside a splitter container.

Currently I am facing a bug when trying to manage variants. The "manage variants" screen is empty.

I think this issue occurs because the ALV parent container is not the cl_gui_container=>default_screen, but the splitter screen instead.

Here is an example to reproduce this issue.

REPORT ztest.

* Referenzen auf GUI-Objekte
* Splitter
DATA: o_splitter_main TYPE REF TO cl_gui_splitter_container.
* Splitter-Container oben
DATA: o_container_o   TYPE REF TO cl_gui_container.
* Splitter-Container unten
DATA: o_container_u   TYPE REF TO cl_gui_container.

* Splitter auf default_screen erzeugen
*https://www.abapforum.com/forum/viewtopic.php?t=25748
o_splitter_main = NEW #( parent                  = cl_gui_container=>default_screen
                         no_autodef_progid_dynnr = abap_true
                         rows                    = 2
                         columns                 = 1 ).

* Höhe oberer Splitter in %
o_splitter_main->set_row_height( id = 1 height = 50 ).
o_container_o = o_splitter_main->get_container( row = 1 column = 1 ).        " MAIN VIEW
o_container_u = o_splitter_main->get_container( row = 2 column = 1 ).        " DETAIL VIEW


START-OF-SELECTION.
* Daten holen
  SELECT *
    INTO TABLE @DATA(it_spfli)
    FROM spfli.

* ALV-Gitter-Objekt erzeugen
  DATA(o_alv) = NEW cl_gui_alv_grid( i_parent      = o_container_o " in default container einbetten
                                     i_appl_events = abap_true ).                     " Ereignisse als Applikationsevents registrieren

* Feldkatalog automatisch durch SALV-Objekte erstellen lassen
  DATA: o_salv TYPE REF TO cl_salv_table.

  cl_salv_table=>factory( IMPORTING
                            r_salv_table = o_salv
                          CHANGING
                            t_table      = it_spfli ).

  DATA(it_fcat) = cl_salv_controller_metadata=>get_lvc_fieldcatalog( r_columns      = o_salv->get_columns( )
                                                                     r_aggregations = o_salv->get_aggregations( ) ).

  DATA(lv_layout) = VALUE lvc_s_layo(
                                        zebra      = abap_true
                                        cwidth_opt = 'A'
                                        grid_title = 'Testapp'
                                      ).

  DATA ls_variant_det TYPE disvariant.
  ls_variant_det-report   = sy-repid.
  ls_variant_det-username = sy-uname.
  .

* ALV anzeigen
  o_alv->set_table_for_first_display( EXPORTING
                                        i_bypassing_buffer = abap_false  " Puffer ausschalten
                                        i_save             = 'A'         " Anzeigevariante sichern
                                        is_layout          = lv_layout   " Layout
                                        is_variant         = ls_variant_det

                                      CHANGING
                                        it_fieldcatalog    = it_fcat     " Feldkatalog
                                        it_outtab          = it_spfli ). " Ausgabetabelle

* Focus auf ALV setzen
  cl_gui_alv_grid=>set_focus( control = o_alv ).
*
** leere SAP-Toolbar ausblenden
  cl_abap_list_layout=>suppress_toolbar( ).
*
** erzwingen von cl_gui_container=>default_screen
  WRITE: space.

enter image description here

Choose Layout, Change Layout and Save Layout are working.


Solution

  • I'm not going to recommand using this "fix". Put it on a dynpro and don't use the no_autodef_progid_dynnr in the cl_gui_splitter_container. It's really prone to error, when you try abusing the default screen with standard screens.

    Here is what you can do. Put everything in the initialization event (or any event before the selection screen) add a dummy parameter to force the selection screen and remove the no_autodef_progid_dynnr from the constructor. The default screen set in there is the standard selection screen 1000. So it will overlay the splitter on the selection screen. The variant management then uses a different screen and you'll see it. Here is the "fixed" example:

    report ztest.
    * Referenzen auf GUI-Objekte
    * Splitter
    data: o_splitter_main type ref to cl_gui_splitter_container.
    * Splitter-Container oben
    data: o_container_o   type ref to cl_gui_container.
    * Splitter-Container unten
    data: o_container_u   type ref to cl_gui_container.
    
    parameters: dummy.
    
    initialization.
    * Splitter auf default_screen erzeugen
    *https://www.abapforum.com/forum/viewtopic.php?t=25748
      o_splitter_main = new #(
                               parent = cl_gui_container=>default_screen
    *                           no_autodef_progid_dynnr = abap_true
                               rows                    = 2
                               columns                 = 1 ).
    
    * Höhe oberer Splitter in %
      o_splitter_main->set_row_height( id = 1 height = 50 ).
      o_container_o = o_splitter_main->get_container( row = 1 column = 1 ).
      o_container_u = o_splitter_main->get_container( row = 2 column = 1 ).
    
    * Daten holen
      select *
        into table @data(it_spfli)
        from spfli.
    
    * ALV-Gitter-Objekt erzeugen
      data(o_alv) = new cl_gui_alv_grid( i_parent      = o_container_o " in default container einbetten
                                         i_appl_events = abap_true ).                     " Ereignisse als Applikationsevents registrieren
    
    * Feldkatalog automatisch durch SALV-Objekte erstellen lassen
      data: o_salv type ref to cl_salv_table.
    
      cl_salv_table=>factory( importing
                                r_salv_table = o_salv
                              changing
                                t_table      = it_spfli ).
    
      data(it_fcat) = cl_salv_controller_metadata=>get_lvc_fieldcatalog( r_columns      = o_salv->get_columns( )
                                                                         r_aggregations = o_salv->get_aggregations( ) ).
    
      data(lv_layout) = value lvc_s_layo(
                                            zebra      = abap_true
                                            cwidth_opt = 'A'
                                            grid_title = 'Testapp'
                                          ).
    
      data ls_variant_det type disvariant.
      ls_variant_det-report   = sy-repid.
      ls_variant_det-username = sy-uname.
      .
    
    * ALV anzeigen
      o_alv->set_table_for_first_display( exporting
                                            i_bypassing_buffer = abap_false  " Puffer ausschalten
                                            i_save             = 'A'         " Anzeigevariante sichern
                                            is_layout          = lv_layout   " Layout
                                            is_variant         = ls_variant_det
    
                                          changing
                                            it_fieldcatalog    = it_fcat     " Feldkatalog
                                            it_outtab          = it_spfli ). " Ausgabetabelle
    
    * Focus auf ALV setzen
      cl_gui_alv_grid=>set_focus( control = o_alv ).
    *
    ** leere SAP-Toolbar ausblenden
      cl_abap_list_layout=>suppress_toolbar( ).
    *
    ** erzwingen von cl_gui_container=>default_screen
    *  write: space.