Skip to Content
avatar image
Former Member

Sort functionality using MULTIPLE columns in a table control

Hi all,

I have a custom screen with table control.Now i need to provide SORT functinality in this screen for the columns in the table control.

My questins:

1.Is it possible to seelct MULTIPLE columns in a table control for SORTING?If yes,what explicit settings do i need to do while creatng the TABEL CONTROL in the screen?DO I need to select "Column selection " as MULTIPLE??

2.How do I write the code for SORT functinonality for multiple columns?

I know how to write the code for SORTING on basis of single column .

Thanks!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 13, 2010 at 04:28 AM

    I did the same application by providing a a wort button, whenever user clicks sort a pop up window will

    appear and there it displays all fields of table then i select which fields to be sorted and sort them.

    SET PF-STATUS '300'.

    SET TITLEBAR 'SORTING'.

    WINDOW STARTING AT 10 10

    ENDING AT 40 20.

    w_char = space.

    WRITE: w_char AS CHECKBOX, 'carrid',

    / w_char AS CHECKBOX, 'connid',

    / w_char AS CHECKBOX, 'cityfrom',

    / w_char AS CHECKBOX, 'cityto',

    / w_char AS CHECKBOX, 'airpfrom',

    / w_char AS CHECKBOX, 'airpto',

    / w_char AS CHECKBOX, 'countryfr',

    / w_char AS CHECKBOX, 'countryto'.

    • if the above are my table fields then i will show them in pop up window and for selection i give checkbox option

    then in do loop.

    READ LINE sy-index FIELD VALUE w_char.

    if w_char is X then add that field to a variable..and like wise

    finally sort all selected fields and push the data to table controller.

    i hope it helps.

    Regards and Best wishes.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi andy once u get all the fields then you can sort dynamycally.

      example of dynamic sort;

      sort t_sflight by (f1) ascending (f2) ascending <.....fn>.

      I hope it helped you.

      Regards and Best wishes.

  • avatar image
    Former Member
    Apr 12, 2010 at 09:02 PM

    Yes, you can sort on multiple columns, but you will have to have an additional popup to get the sort fields and the order that the fields should be sorted.

    Rob

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Rob,

      Thanks for the reply.

      However I was thinking to apply the same logic as for single columns as follows:

      types : begin of ty_fields,
                  c_fieldname(20),
                 end of ty_fields.
      
      data  : t_fields type table of ty_fields,
                 wa_fields like line of t_fields.
      
      WHEN 'SORTUP'.(Ascending)
      
            loop at TABLE tc01-cols INTO wa_tc01  where  selected = 'X'.
            SPLIT wa_tc01-screen-name AT '-' INTO g_help g_fieldname.
            wa_fields-c_fieldname = g_fieldname.
            append wa_fields to t_fields.
            endloop.
            
            describe table t_fields lines l_index.
            c_count = 1.
            if c_count  <= l_index.
            read table t_fields into wa_fields index c_count.
            case c_count.
      
            when '1'.
            l_field1 = wa_fields-c_fieldname.
      
            when '2'.
           l_field2 = wa_fields-c_fieldname.
      
          and so on depending on the no of columns in the table control...
      
            endcase.
            endif.
            SORT t_tvbdpl_scr BY  l_fields1 l_fields 2......l_fieldn.

      Let me know if the above method will work!Also for the above method to work will the type of fields(columns on whihc sort function will be applied) matter???

      Thanks again for your time.