How to set Sort Order in ABAP ALV with IDA on HANA



    Hello everyone, In our previous tutorials we introduced you to the new flavor of ABAP ALV called ALV with Integrated Data Access(IDA). In this tutorial you will learn how to set the default sorting to the ALV with IDA on HANA. Lets get started. Below is the method which we can use to display the sorted ALV with IDA on HANA.

    [perfectpullquote align=”full” cite=”” link=”” color=”#7ad03a” class=”” size=”18″]SET_SORT_ORDER( ) in interface IF_SALV_GUI_LAYOUT_IDA[/perfectpullquote]

    To set the sorting order to ALV with IDA

    1. Get the reference object of Layout by calling the method DEFAULT_LAYOUT( ) in interface IF_SALV_GUI_TABLE_IDA.
    2. Define the sorting rule by adding the column name, sorting order
    3. Set the sorting rule to the ALV to the layout by calling the method SET_SORT_ORDER().

    Step-by-Step Procedure

    Create an ABAP Program in Eclipse.Enter Name, Description and click on Next.

    New ABAP Program

    2. In the Selection of Transport Request window, choose the transport request. As we are saving the program in $TMP package in our case no transport request is required.Click on Finish.

    Selection of Transport Request

    3. Copy and paste the below code.

    *                         *
    *            Sorting in ABAP ALV with IDA              *
    *1. Create object reference for ALV with IDA
    DATA(lo_alv_display) = cl_salv_gui_table_ida=>create( 
                                                  iv_table_name = 'SNWD_PD' ).
    *2. Get ALV Layout reference
      DATA(lo_layout) = lo_alv_display->default_layout( ).
    *3. Define Sorting rule
    DATA(lt_sort_rule) = VALUE if_salv_gui_types_ida=>yt_sort_rule(
                               ( field_name = 'CATEGORY' 
                                 descending = abap_false )).
    *4. Set Sorting rule to the ALV
    lo_layout->set_sort_order( it_sort_order = lt_sort_rule ).
    *5. Display ALV
      lo_alv_display->fullscreen( )->display( ).


    4. Activate and Execute the ABAP program.

    5. Below is the output before applying sorting rule on the column “Category”.


    6. Below is the output after applying sorting rule on the column “Category”.


    Congrats! You have successfully learned how to set Sort Order in ABAP ALV with IDA on HANA. Please stay tuned for ALV with IDA for HANA tutorials. Leave a comment in the below comment section and let us know your feedback.