Cutter
Cutter

Reputation: 1820

How to display a SALV in a splitting container bound to cl_gui_container=>default_screen

Sorry for the extremely simple question, by I can't seem to display a SALV table in a splitting container bound to cl_gui_container=>default_screen.

Minimal code:

DATA: lo_salv_table type ref to cl_salv_table,
      lo_splitter   type ref to cl_gui_splitter_container.

  SELECT * FROM SFLIGHT UP TO 200 ROWS INTO TABLE @data(sflight).

  lo_splitter = new cl_gui_splitter_container(
    parent                  = cl_gui_container=>default_screen
    rows                    = 1
    columns                 = 2
  ).

  cl_salv_table=>factory( EXPORTING r_container   = lo_splitter->get_container(
                                                      row    = 1
                                                      column = 1
                                                    )
                          IMPORTING r_salv_table  = lo_salv_table
                          CHANGING t_table        = sflight ).

  lo_salv_table->display( ).

The program runs and returns but nothing happens.

I've looked on the web, all examples look like the code above (examples here and here)

Thanks for your help.

Upvotes: 0

Views: 339

Answers (1)

Sandra Rossi
Sandra Rossi

Reputation: 13656

cl_gui_container=>default_screen is used only if Screen Processing is active. By default, if you run an Executable Program, it's inactive till you run CALL SCREEN, CALL SELECTION-SCREEN or the implicit call of the selection screen 1000.

It's easier to use a selection screen because it's fully embedded in the ABAP language, via the ABAP statements PARAMETERS or SELECT-OPTIONS.

Hence, adding the two lines PARAMETERS dummy and AT SELECTION-SCREEN OUTPUT is sufficient to display the controls:

REPORT.
PARAMETERS dummy.             " <=========
AT SELECTION-SCREEN OUTPUT.   " <=========
DATA: lo_salv_table type ref to cl_salv_table,
      lo_splitter   type ref to cl_gui_splitter_container.

  SELECT * FROM SFLIGHT UP TO 200 ROWS INTO TABLE @data(sflight).

  lo_splitter = new cl_gui_splitter_container(
    parent                  = cl_gui_container=>default_screen
    rows                    = 1
    columns                 = 2
  ).

  cl_salv_table=>factory( EXPORTING r_container   = lo_splitter->get_container(
                                                      row    = 1
                                                      column = 1
                                                    )
                          IMPORTING r_salv_table  = lo_salv_table
                          CHANGING t_table        = sflight ).

  lo_salv_table->display( ).

Result: CL_SALV_TABLE in CL_GUI_SPLITTER_CONTAINER

NB: see also How to share a Control Framework demo such a way it can be run by a simple copy/paste?

Example with a normal selection screen, followed by a dummy screen to contain the container:

PARAMETERS any TYPE string.

SELECTION-SCREEN BEGIN OF SCREEN 1001.
PARAMETERS dummy.
SELECTION-SCREEN END OF SCREEN 1001.

AT SELECTION-SCREEN OUTPUT.
  CASE sy-dynnr.
    WHEN 1001.
      SELECT * FROM sflight UP TO 200 ROWS INTO TABLE @DATA(sflight).
      DATA(lo_splitter) = NEW cl_gui_splitter_container( parent  = cl_gui_container=>default_screen
                                                         rows    = 1
                                                         columns = 2 ).
      cl_salv_table=>factory( EXPORTING r_container  = lo_splitter->get_container( row    = 1
                                                                                   column = 1 )
                              IMPORTING r_salv_table = DATA(lo_salv_table)
                              CHANGING  t_table      = sflight ).
      lo_salv_table->display( ).
  ENDCASE.

START-OF-SELECTION.
  CALL SELECTION-SCREEN 1001.

Upvotes: 0

Related Questions