Skip to Content

expand and collapse total lines in ABAP oo ALV


In classic alv I remember an option to expand total lines (show detail lines) and collapse total lines (hide detail lines) by clicking an icon that looked like a printer icon:

Now I discovered that this option is not available in OO alv - not out of the box anyway. I have searched for options in the field catalog, the layout structure, the styles option, but so far I only found something that seems to be the opposite of what i want.

The is_layout-no_totexp seems to be a flag to set if I want to prevent that total lines is expandable, but I has no influence if I set this flag or not.

How can I have this functionality in OO ALV?

Best regards

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    Mar 28, 2013 at 08:59 PM

    A predefined sort order can be added to the OO ALV (CL_SALV_TABLE) prior to display by doing the following:

    Use the factory method to create the grid and then use method GET_SORTS.

         Ex: lr_sorts = gr_table->get_sorts( ).

    From here you can define the columns that you want subtotaled.

        Ex:  lr_sort->add_sort( columnname = 'GSBER'   subtotal = 'X' sequence = '01' ).

    Sorry I don't have a small test program at this time but the information above should be enough to get you going.

    If you have more questions check out some of SAP's Demo programs like SALV_DEMO_TABLE_EVENTS.

    Also (Shift + Right Double Click) in a grey area of a grid will bring up the Consistency Check of ALV Grid which can be very handy. 

    Good Luck,


    Add comment
    10|10000 characters needed characters exceeded

    • Hi Aron

      fist of all thanks for the hint about Shift + Right Double Click - lot of interesting info to get there.

      I'm using cl_gui_alv_grid and I don't want to change to CL_SALV_TABLE.

      Also I don't want to make predefined sort criteria. The users should be able to choose their own sort criteria and their own sub totals.

  • Mar 27, 2013 at 01:49 PM


    When you add sort and totals.

    You get "drill down total level".


    Clipboard01.png (72.9 kB)
    Add comment
    10|10000 characters needed characters exceeded

  • Mar 27, 2013 at 04:26 PM

    Hello Thomas,

    Are you referring to the icon (Collapse Selection) shown below?

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Sonal

      Thanks for your reply.

      I don't want to program the sort sequence - it should be an option to the users to define their own sort criteria and save them with their own alv layout

      - but anyway I have tried to pass values to the IT_SORT table without result. As you can see there are no option to collapse section (see collapse section image in above post from Aron Kitts) :

      Snap4.jpg (71.4 kB)
  • avatar image
    Former Member
    Mar 28, 2013 at 12:38 PM

    Hi Mr. Thomas   refer this  code.

    IF gs_sub_fcat-fieldname = 'PRCTR'.

      REFRESH : gt_sort.

        wa_sort-fieldname = 'PRCTR'.

        wa_sort-up = 'X'.

        wa_sort-subtot = 'X'.

       wa_sort-tabname = 'gt_ordsub1'.

        wa_sort-expa = 'X'.---------------------------------> This is  importand  for  Expand

       APPEND wa_sort TO gt_sort.

      CLEAR : wa_sort.

    then pass the gt_sort to FM 😊


    Add comment
    10|10000 characters needed characters exceeded

    • Hi Srithar

      The IT_SORT parameter of cl_gui_alv_grid->set_table_for_first_display does not have tabname field, so it seems your code is not for the method I use and I can also see you write "pass the gt_sort> to FM"

      But the IT_SORT in my scenario also has a EXPA field and if I set this flag, the output is presented in a collapsed way (totals only), but still no easy way to expand the lines (except for the option already mentioned by Eitan Rosenberg).


      I suppose I could program my own double-click function - if the user double click the quantity column, I could make the program read current sort table by method get_sort_criteria, toggle the EXPA flag and re-set the sort table by method set_sort_criteria. Hmmmm

      Snap5.jpg (41.6 kB)
  • Apr 04, 2013 at 12:41 PM

    Hi All

    Thanks for all the replies. I didn't get the perfect solution, but I got a lot of useful ideas.

    So thanks again. I will close the thread here.

    Best regards

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Sridhar,

      Thanks for the info. In the code snippet , the entire output is getting merged row-wise . My requirement was to make a collapsible subtotals with a button as in the screen-shot by Aaron Kitts. The user wants to see this report as a Summary of respective columns.I want the exact same scenario as shown in the screen shot. If you have any valuable info on how to do it please let me know.

  • Aug 29, 2014 at 03:15 PM

    may be your grid is editable?

    Add comment
    10|10000 characters needed characters exceeded