Skip to Content

Overview

I was recently presented with a requirement to create an ALV view variant to display only records for the current month. Since the current month would change over time, a selection variable was needed, however the ALV settings dialog of component SALV_WD_TABLE offers no possibility of creating selection criteria with variables.

A search of SCN revealed a similar requirement for selection criteria with variables had been discussed a couple of times but with no solution found. In one discussion however, SAP guru Thomas Jung hinted that it was programmatically possible. This document explores one possible programmatic solution.

This document assumes you have already implemented a component usage for SALV_WD_TABLE to create an ALV. If you would like instructions for creating an ALV in Web Dynpro ABAP, please see document Component Usages in Web Dynpro ABAP Part I: ABAP List Viewer (ALV).

Procedure

1.0 Create an Event Handler for SALV_WD_TABLE event ON_STD_FUNCTION_AFTE

Open the view containing the ALV table, and navigate to its Methods tab. Create an event handler method for event ON_STD_FUNCTION_AFTE of component SALV_WD_TABLE. Choose Method Type Event Handler and use the search help on field Event to select the appropriate event.

demo_alv_var1.JPG

2.0 Implement the Event Handler Method

The signature of the event handler for event ON_STD_FUNCTION_AFTE has the following default parameters. Parameter WDEVENT is the familiar default parameter for event handler methods, and parameter R_PARAM holds a reference to the ALV standard function being executed.

demo_alv_var2.JPG

The code below demonstrates how to identify the ALV view variant currently selected and how to programmatically add a filter to a field of the ALV.


method on_std_function_afte.

    data lo_alv_ifc      type ref to iwci_salv_wd_table.
    data ls_config_in  type if_salv_wd_table=>s_type_param_config_in.
    data ls_config_out type if_salv_wd_table=>s_type_param_config_out.
    data lo_model        type ref to cl_salv_wd_config_table.
    data lo_field          type ref to cl_salv_wd_field.

  * Get the ALV interface controller
    lo_alv_ifc = wd_this->wd_cpifc_alv_table( ).

    case r_param->id.
  *    Handle selection of an ALV view variant
        when if_salv_wd_c_std_functions=>view_load " select view from view dropdown
            or if_salv_wd_c_std_functions=>settings.    " select view from settings > ok/apply

  *        Determine what ALV view variant is currently selected
            ls_config_in-action = if_salv_wd_table=>actual.
            ls_config_out = lo_alv_ifc->get_config_data( ls_config_in ).

  *        Process each ALV view variant as needed
            case ls_config_out-view-description.
                when 'MY_ALV_VIEW_VARIANT'.
  *                Fetch the field we will be creating a filter for
                    lo_model = lo_alv_ifc->get_model( ).
                    lo_field = lo_model->if_salv_wd_field_settings~get_field( 'FIELD_NAME' ).

  *                Remove prior filter rules on the field
                    if lo_field->if_salv_wd_filter~t_filter[] is not initial.
                        lo_field->if_salv_wd_filter~delete_filter_rules( ).
                    endif.

  *                Set new filter rule on the field
                    lo_field->if_salv_wd_filter~create_filter_rule(
                        operator    = 'BT'
                        low_value  = low_date_value
                        high_value = high_date_value ).

                when others. " other view variants

            endcase. " view variant

        when others. " other standard functions

    endcase. " ALV standard function

endmethod.

Result

After selecting the programmatically altered view from the ALV view dropdown, the ALV table displays only those records allowed by the added filter. In the screen shots below, ALV view variant TEST_ALV_VARIANT has been altered to include only records with a start date in August 2013.

demo_alv_var3.JPG

demo_alv_var4.JPG

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply