Application Development and Automation 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: 
Read only

Class CL_SALV_FUNCTIONS, method ENABLE_FUNCTION not supported

Former Member
0 Likes
18,208

Hi all

I am trying to add function to the CL_SALV_TABLE as following:

START-OF-SELECTION.
  TRY.
      PERFORM query.
      IF gt_kep_alv[] IS INITIAL.
        WRITE:/ text-002.
        EXIT.
      ENDIF.
      cl_salv_table=>factory(
        IMPORTING
          r_salv_table = DATA(lo_alv)
        CHANGING
          t_table      = gt_kep_alv[] ).
      DATA(lo_func) = lo_alv->get_functions( ).
      lo_func->set_all( abap_true ).
      lo_func->add_function( name = CONV salv_de_function( 'REFRESH' )
                             icon = '@42@'
                             text = CONV string( text-005 )
                             tooltip = CONV string( text-005 )
                             position = if_salv_c_function_position=>right_of_salv_functions
                            ).
      DATA(lo_layout) = lo_alv->get_layout( ).
      DATA(ls_key) = VALUE salv_s_layout_key( report = sy-repid ).
      lo_layout->set_key( ls_key ).
      lo_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
      DATA(lo_column_gleis) = lo_alv->get_columns( )->get_column( columnname = 'GLEIS' ).
      lo_column_gleis->set_short_text( value = text-003 ).
      lo_column_gleis->set_medium_text( value = text-003 ).
      lo_column_gleis->set_long_text( value = text-003 ).
      DATA(lo_column_status) = lo_alv->get_columns( )->get_column( columnname = 'STATUS' ).
      lo_column_status->set_short_text( value = text-004 ).
      lo_column_status->set_medium_text( value = text-004 ).
      lo_column_status->set_long_text( value = text-004 ).
      DATA(lo_events) = lo_alv->get_event( ).
      DATA(lo_event) = NEW gcl_event_handler( ).
      SET HANDLER lo_event->handle_toolbar_click FOR lo_events.
      lo_alv->display( ).
    CATCH cx_salv_msg INTO DATA(lo_msg).
      WRITE:/ lo_msg->get_text( ).
    CATCH cx_salv_method_not_supported INTO DATA(lo_salv).
      WRITE:/ lo_salv->get_text( ).
  ENDTRY.
FORM query.
......
......
......
ENDFORM.

When I carry out the application, I've got:

Class CL_SALV_FUNCTIONS, method ENABLE_FUNCTION not supported for REFRESH Only Possible in Grid View 

What am I doing wrong?

Thanks

3 REPLIES 3
Read only

matt
Active Contributor
11,058

This has been discussed quite a few times. I believe Paul Hardy has a blog on it. Essentially, you can't do it that way, but there are workarounds.

Personally I just use CL_GUI_ALV_GRID instead if I need user defined functions.

By the way - FORM and PERFORM are obsolete... try using classes and methods.

Read only

Sandra_Rossi
Active Contributor
11,058

zero_coder In fact, it doesn't mean that you can't use ADD_FUNCTION with SALV for adding a button to the toolbar, but that this method works only with the SALV grid view mode (inside a GUI container).

In your case, your FACTORY call indicates that you are using the "full screen" mode.

ADD_FUNCTION works only if you define a custom screen with a "custom" container (would work for any other kind of container too) and you instantiate like that:

      CALL METHOD cl_salv_table=>factory
        EXPORTING
          r_container  = go_container " <== type ref to cl_gui_container
        IMPORTING
          r_salv_table = DATA(lo_alv)
        CHANGING
          t_table      = gt_kep_alv[].

There is a workaround with the "full screen" mode : copy the standard GUI status (SALV_TABLE_STANDARD of program SAPLSLVC_FULLSCREEN), add a static button, and communicate the GUI status at runtime by calling LO_ALV->SET_SCREEN_STATUS( ... )

Read only

DoanManhQuynh
Active Contributor
0 Likes
11,058

Take a look at program: SALV_DEMO_TABLE_EVENTS, you will know how to define your own function with anykind of screen mode