6

I've created a simple ALV grid and populated the grid with data, now the grid is displayed after the selection screen. I'm not using custom container and display the grid in full screen.

Is there a property of ALV grid object that enables toolbar with buttons filter, sort, etc, that is normally on top of the grid?

So far this is what I have:

TRY.
  cl_salv_table=>factory(
    IMPORTING
      r_salv_table   = gr_alv
    CHANGING
      t_table        = tbl_data
      ).
CATCH cx_salv_msg.
ENDTRY.

* initialize the alv settings - nothing done here for the moment.
PERFORM define_settings USING gr_alv.

* Display the ALV
gr_alv->display( ).
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
JordinB
  • 306
  • 1
  • 2
  • 13

4 Answers4

8

Each ALV function is implemented as a separate CLASS in Simple ALV, so you have to handle them separately. You do not need a custom control.

In order to add the toolbar:

data: lr_func TYPE REF TO CL_SALV_FUNCTIONS_LIST.
"Functions
lr_func = gr_alv->get_functions( ).
lr_func->set_all( ).

Complete ALV display:

form display_results.

  data: ls_key        type salv_s_layout_key,

        lo_table      type ref to cl_salv_table,
        lo_cols       type ref to cl_salv_columns_table,
        lo_events     type ref to cl_salv_events_table,
        lo_funcs      type ref to cl_salv_functions_list,
        lo_layout     type ref to cl_salv_layout,
        lo_display    type ref to cl_salv_display_settings,
        lo_selections type ref to cl_salv_selections.

  try.
      call method cl_salv_table=>factory
        exporting
          list_display = abap_false
        importing
          r_salv_table = lo_table
        changing
          t_table      = gt_list.
    catch cx_salv_msg .                                 "#EC NO_HANDLER
  endtry.
  "Events
  create object go_events.
  lo_events = lo_table->get_event( ).
  set handler go_events->double_click for lo_events.

  "Layouts
  ls_key-report = sy-repid.
  lo_layout = lo_table->get_layout( ).
  lo_layout->set_key( ls_key ).
  lo_layout->set_default( abap_true ).
  lo_layout->set_save_restriction( ).
  lo_layout->set_initial_layout( p_var ).

  lo_cols = lo_table->get_columns( ).
  perform change_columns changing lo_cols.

  "Functions
  lo_funcs = lo_table->get_functions( ).
  lo_funcs->set_all( ).

  "Display Settings
  lo_display = lo_table->get_display_settings( ).
  lo_display->set_striped_pattern( abap_true ).

  "Selections
  lo_selections = lo_table->get_selections( ).
  lo_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

  lo_table->display( ).
endform.                   " DISPLAY_RESULTS
Esti
  • 3,677
  • 8
  • 35
  • 57
  • 2
    It's worth noting that there are other methods for setting smaller sets of toolbar functions if you don't want all the export options for example. **SET_GROUP_SORT** for all the sort options, **SET_PRINT** for printing. Mostly self-explanatory. – nath Oct 06 '15 at 11:31
3

This is confusing at first when you use the ALV object model. If you use the ALV in fullscreen mode you have to reference a GUI status in your program, and use the method SET_SCREEN_STATUS on your grid instance. It's explained in the SAP Help here.

It helps to copy the GUI status SALV_TABLE_STANDARD from function group SALV_METADATA_STATUS into your report as a starting point, and then you can remove any functions you don't need. For example, if you copied the status into your program as ALV_STATUS, you would write:

gr_alv->set_screen_status( report   = sy-repid
                           pfstatus = 'ALV_STATUS' ).

If you want to use the class-based model of setting up ALV functions, you have to embed the grid object in a custom container in a screen.

nath
  • 178
  • 1
  • 3
  • I believe set_screen_status is only required if you want to add your own commands to the toolbar. The default ALV functions are supplied by class CL_SALV_FUNCTIONS_LIST – Esti Jul 18 '11 at 07:03
  • SET_SCREEN_STATUS can be used but take care, it aborts if called for "Grid Output" -> "Class CL_SALV_TABLE, method SET_SCREEN_STATUS not supported for CL_SALV_TABLE in Grid Output" (CX_SALV_METHOD_NOT_SUPPORTED) – Michael Biermann Jul 25 '17 at 16:11
2

Seems what you need to do is get an instance of CL_SALV_FUNCTIONS_LIST from your grid object like so:

data: lr_func TYPE REF TO CL_SALV_FUNCTIONS_LIST.
lr_func = gr_alv->get_functions( ).
lr_func->set_all( ).

But, from there, it seems you need to do a bit or work. My advice: Look at the documentation on classes CL_SALV_TABLE and CL_SALV_FUNCTIONS_LIST (that is, click the documentation button when you display the class in transaction SE24). The latter tells you exactly what you need to do.

(Also, a little hint: Put your processing logic inside the try-catch block, because if the initialization fails, you might catch that exception but go on to try call a method on an uninstantiated or uninitialized class).

Esti
  • 3,677
  • 8
  • 35
  • 57
mydoghasworms
  • 18,233
  • 11
  • 61
  • 95
  • You're just missing the lr_func->set_all method call I think. It is unfortunate that whoever marked you down didn't do a bit of research of their own :D. – Esti Jul 04 '11 at 20:57
  • Thanks. I haven't used the CL_SALV functions myself, having always relied on CL_GUI_ALV_GRID, so my information could be a bit lacking. But anyway, the documentation is quite good on the CL_SALV classes. – mydoghasworms Jul 05 '11 at 06:05
0
  • add a customer container to your gui
  • create an object of the class cl_gui_custom_container and supply the name of your container
  • create an instance of the class cl_gui_alv_grid and supply the custom container object
  • use the method set_table_for_first_display

this will display a toolbar with all buttons. you can control which buttons you want in the toolbar with the IT_TOOLBAR_EXCLUDING parameter to the set_table_for_first_display method.