When using ALV reporting, you can allow your end user to change around columns, set the colums to sort on and even define aggregate (totalling) settings. The user can also store these settings as a default for the user, or even as default to all users (who don't have a user setting). These column settings are called Layouts, and they should be made available before they can be used:
Layouts are stored somewhere which is probably why SAP is not making these options available as a default. To utilize ALV's full potential: I would advise to enable storing layouts by the end user available on all ALV reports. In some cases it may not be a good idea to allow end users to alter the global default, for which a restriction can be set.
data: lrf_layout type ref to cl_salv_layout, lva_layout_key type salv_s_layout_key. lrf_layout = go_salv->get_layout( ). lva_layout_key-report = sy-cprog. lva_layout_key-logical_group = 'ABCA'. "<= your own key code here * The key for layouts needs to be set to enable it's functionality. lrf_layout->set_key( lva_layout_key ). lrf_layout->set_default( abap_true ). lrf_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
If all goes well a few extra buttons should become available on your ALV list which can be used to change layout, store as alternative or even as default. Note that method
set_save_restriction (above) can be used to deny the end user passage to the global layout settings.
It could be handy to have a layout setting relation with a selection screen variant, for which you will want F4 functionality in place. Here's how:
PARAMETER pa_layou type disvariant-variant. at selection-screen on value-request for pa_layou. lcl_worx=>layouts_f4( changing c_variant = pa_layou ).
Where the method (of lcl_worx) does the F4 popup work. You may want to also fill in
method layouts_f4. data: ls_variant type disvariant, lv_exit type char1. ls_variant-report = sy-repid. CALL FUNCTION 'REUSE_ALV_VARIANT_F4' EXPORTING is_variant = ls_variant i_save = 'A' IMPORTING e_exit = lv_exit es_variant = ls_variant EXCEPTIONS not_found = 2. if sy-subrc = 2. message id sy-msgid type 'S' number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. else. if lv_exit eq space. c_variant = ls_variant-variant. endif. endif. endmethod.
Of course your method could also be set up as a routine. Check SAP example
BCALV_TEST_GRID, packed with ALV features.
If you ever get into trouble with e.g. a globally defined layout with references that are no longer valid because column names have been changed: table
LTDX holds the layout information. Remove (entries) and be done with it.