Sort alv column

I have an alv table.
This is sorted ascending by the first column called "first" . I want to sort it descending by first colum.
How can I do that?
Thanks for help!!

Hi Ezachiael,
You need to use the create_sort_rule method of if_salv_wd_sort for achieving this sorting functionality. Refer to the code snippet below which am using inside the WDDOINIT method to sort the SEATSOCC field by descending order.
Regards,
Uday
METHOD wddoinit .
* Create component usage for alv component
  DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.
  l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
    l_ref_cmp_usage->create_component( ).
  ENDIF.
* Get config model
  DATA: l_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table .
  l_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).
  DATA: l_value TYPE REF TO cl_salv_wd_config_table.
  l_value = l_ref_interfacecontroller->get_model( ).
* set visible row count
  l_value->if_salv_wd_table_settings~set_visible_row_count( '5' ).
* Sort rows by seatsocc descending
  DATA: lr_field  TYPE REF TO cl_salv_wd_field.
  lr_field = l_value->if_salv_wd_field_settings~get_field( 'SEATSOCC' ).
  lr_field->if_salv_wd_sort~create_sort_rule( sort_order =
  if_salv_wd_c_sort=>sort_order_descending ).
ENDMETHOD.

Similar Messages

  • ALV sort any column in fieldcatalog by default

    hi all
    i have developed report in ALV format. i have total 8 columns
    normally we sort any column in the output only.
    i have requirement that instead of sorting manually any column say Material no
    it should be sorted by default when user execute the report. he should not do manually by pressing Sort button in
    alv list
    give code for refrence

    hi u can use the IT_SORT parameter of the FM REUSE_ALV_GRID_DISPLAY for this purpose.
    specify the fields for which u need to sort ur table and the sorting order
    ( I have jst given da example for one field but this it_sort table can hav more than one fields.)
      gs_alv_sort-spos = 1.
      gs_alv_sort-fieldname = 'VKORG'.            " Sales Org
      gs_alv_sort-up = 'X'.                       " Ascending
      APPEND gs_alv_sort TO gt_alv_sort.
    then pass this internal table to teh alv fm
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         I_CALLBACK_PROGRAM                = wf_repid
       I_CALLBACK_HTML_TOP_OF_PAGE       = 'HTML_TOP_OF_PAGE'
       I_BACKGROUND_ID                   = 'WEAVE_BACKGROUND'
       IS_LAYOUT                         = gs_alv_layout
       IT_FIELDCAT                       =  gt_alv_fieldcat
       IT_SORT                           =  gt_alv_sort
        TABLES
          T_OUTTAB                          = it_output
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2

  • Do not allow to sort some columns in Alv Grid

    Dear friends,
    Please help me.
    I want to tell to the method set_table_for_first_display - make one of the columns not sortable.  Let's say the column name is "My Icon".
    What I mean with that is:
    when User will highlight column "My icon" and then click on sort buttons in the toolbar - no sort will happen on this column.
    I was trying to identify a field in lvc_s_sort which would say "do not sort this column".  Is there any?
    Or the only way to accomplish my task is to make sort buttons in the toolbar disable if column "My Icon" is clicked?
    gt_sort      TYPE lvc_t_sort.
        CALL  METHOD grid1->set_table_for_first_display
             EXPORTING i_structure_name = 'IT'
                       is_layout        = gs_layout
                       is_print         = gs_print
             CHANGING  it_outtab        = it
                       it_fieldcatalog  = gt_fcat
                       it_sort = gt_sort
    Thank you,
    Tatyana.

    Got a solution for ya, but you have to handle it thru coding.   So you will need to handle an event from your ALV grid. 
    First thing is that you need a local class as your event handler,  copy and paste this code.  Here we are using the name ALV_GRID for your alv object
    data: alv_grid       type ref to cl_gui_alv_grid.
    *       CLASS lcl_event_receiver DEFINITION
    class lcl_event_receiver definition.
      public section.
        methods handle_user_command
          for event before_user_command of cl_gui_alv_grid
          importing e_ucomm.
      private section.
    endclass.
    *       CLASS lCL_EVENT_RECEIVER IMPLEMENTATION
    class lcl_event_receiver implementation.
      method handle_user_command.
        data: icols type lvc_t_col,
              xcols like line of icols.
    * Get the currently selected column
        call method alv_grid->get_selected_columns
           importing
             et_index_columns = icols.
        read table icols into xcols index 1.
    * If the selected column is not one that should be sorted
        check xcols-fieldname = 'MATNR'.    "<-- Whatever columns that you don't want to allow sorting on.
    * Now check the function code, if sort ascending or descending, then give message
        check e_ucomm = cl_gui_alv_grid=>mc_fc_sort_asc
          or  e_ucomm =  cl_gui_alv_grid=>mc_fc_sort_dsc.
        message i001(00) with 'Can not sort on this column'.
    * Now set the UCOMM as if the user didn't click anything.
        call method alv_grid->set_user_command( space ).
      endmethod.
    endclass.
    data: event_receiver type ref to lcl_event_receiver.
    Also, you will need to set the event hanlder after calling the SET_TABLE_FOR_FIRST_DISPLAY.
      call method alv_grid->set_table_for_first_display
          changing
               it_outtab       = i_alv[]
               it_fieldcatalog = ifc[].
    *  Set the handler for ALV grid
      create object event_receiver.
      set handler event_receiver->handle_user_command for alv_grid.
    Just tested this, and works quite well.
    Regards,
    Rich Heilman

  • ALV: How to sort multiple columns?

    Hi all,
    Good morning!
    I have a requirement to sort multiple columns in ALV. I did a search and tried with following codes:
    data: lo_config_alv  type ref to cl_salv_wd_config_table.
    lo_config_alv->if_salv_wd_table_settings~set_multi_column_sort( value = abap_true ).
    But I still can not sort for multiple columns.
    Please guide me how to do that.
    Thanks,
    Khanh

    Hello,
    If you want to sort ALV by multiple fields, then you have to create sort rule for each field and set sort position for each field to specify the sequence in which you want to sort multiple columns.
    Here is a sample code:
    * Sort rows by PRICE descending
      DATA: lr_field1 TYPE REF TO cl_salv_wd_field.
      DATA: lr_rule1 TYPE REF TO CL_SALV_WD_SORT_RULE.
      lr_field1 = lv_value->if_salv_wd_field_settings~get_field( 'PRICE' ).
      lr_field1->if_salv_wd_sort~create_sort_rule( EXPORTING sort_order = if_salv_wd_c_sort=>sort_order_descending
                                                   RECEIVING value = lr_rule1 ).
      lr_rule1->set_sort_position(  2 ). "set the sort position to 2
    * Sort rows by seatsmax descending
      DATA: lr_field2 TYPE REF TO cl_salv_wd_field.
      DATA: lr_rule2 TYPE REF TO CL_SALV_WD_SORT_RULE.
      lr_field2 = lv_value->if_salv_wd_field_settings~get_field( 'SEATSMAX' ).
      lr_field2->if_salv_wd_sort~create_sort_rule( EXPORTING sort_order = if_salv_wd_c_sort=>sort_order_descending
                                                              RECEIVING value = lr_rule2 ).
      lr_rule2->set_sort_position( 1 ). "set the sort position to 1
    * Sort rows by seatsocc descending
      DATA: lr_field TYPE REF TO cl_salv_wd_field.
      DATA: lr_rule3 TYPE REF TO CL_SALV_WD_SORT_RULE.
      lr_field = lv_value->if_salv_wd_field_settings~get_field( 'SEATSOCC' ).
      lr_field->if_salv_wd_sort~create_sort_rule( EXPORTING sort_order = if_salv_wd_c_sort=>sort_order_descending
      RECEIVING value = lr_rule3 ).
      lr_rule3->set_sort_position( 3 ). "set the sort position to 3
    In the above code, the sequence of sorting would be seatsmax price seatsocc
    If you dont specify the sort position, then the sequence of sorting would be the order in which the sort rules are created.
    In the above example, if we didnt set sort positions for the fields, then order would be price seatsmax seatsocc.
    Refer to this link for more info: https://cw.sdn.sap.com/cw/docs/DOC-33859
    Hope this helps!
    Regards,
    Srilatha

  • Print Issue with Sorted ALV Grid

    Hi Team,
    I am using ALV display for my Program. Iam using REUSE_ALV_GRID_DISPLAY. Also i have a Sorting condition for my ALV grid. So iam filling the Sort table & passing it to the Function module. The data is displayed correctly with Sorting as required in the Output.
    Now the issue is with: Print from this ALV. When we try to print the data, The requirement is that the Print should be same as how it is displayed in the ALV. "Grouped Columns"..... But now, the Print is that all the data is filled in all the columns. But user wants the Print also to appear  same as it is shown in a Sorted ALV display.(With some similar column data missing in succeding sort columns until new entry starts)
    Please suggest a solution to acheive the same.
    Thanks & regards,
    Chaitanya

    Look at Q#19 in the note 1009650. Merging functionality is available only for ALV grid display.
    Related Note: 447055
    Work around would be to display the excel in the SAP window (Excel in Place)  and print it from Excel. Read the following thread to make the necessary settings to make it work. Download Report exactly same as seems with Layout set !!
    Edited by: Jeevan Sagar on Jan 19, 2012 12:38 AM

  • Group Sort ALV

    Hi,
    Is it possible to group sort on ALV?
    it seems we are able to merge together several rows via sort but only on its field level.  is it possible to be a group field level?
    example if i sort PO number first and vendor second it will have individual PO and the vendor field is merge together if it is the same with a different PO.  Can we make the PO number as the first priority sorting without changing the position of the fields?

    c z wrote:
    Hi,
    >
    > Is it possible to group sort on ALV?
    >
    > it seems we are able to merge together several rows via sort but only on its field level.  is it possible to be a group field level?
    >
    > example if i sort PO number first and vendor second it will have individual PO and the vendor field is merge together if it is the same with a different PO.  Can we make the PO number as the first priority sorting without changing the position of the fields?
    If I have understood your requirement correctly, group sorting should be as simple as filling up the 'IT_SORT' parameter(REUSE_ALV_GRID_DISPLAY/REUSE_ALV_LIST_DISPLAY/CL_GUI_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY)
    as shown below: (please let me know if I have misunderstood your requirement).
    ls_sort-spos = '1'.
      ls_sort-fieldname = 'FIELD1'.
      ls_sort-up = 'X'.
      APPEND ls_sort TO it_sort.
      CLEAR ls_sort.
      ls_sort-spos = '2'.
      ls_sort-fieldname = 'FIELD2'.
      ls_sort-up = 'X'.
      APPEND ls_sort TO it_sort.
      CLEAR ls_sort.
    Even after displaying the ALV, columns can be group sorted by selecting all of them together(by dragging the cursor over all the columns that need to be sorted)
    -Rajesh.

  • Suppress leading zeros for ALV column

    Hello,
    I have an ALV with a column mapped to a context attribute of type NUMC and would like to suppress the leading zeros being displayed.  My initial solution was to change the attribute to a char/string type and remove the zeros in my code, but then, the sort functionality no longer works correctly.  Any ideas if the ALV can use a 'hidden' field to do the sorting for a certain column... that way, I can display the number as a char/string without the zeros and when the user sorts the column, the ALV will use the hidden NUMC type field.
    Thanx for any directions...

    Hi,
    You can follow the following way which i implemnted for one of my application. Here i am setting this property for the context attrubute. May be this will work. But in ALV there is no separate method for this type of setting.
    **This method is used to display the Leading zeros for the Lot Number in Step-1
      DATA:
        node_do_not_change                  TYPE REF TO if_wd_context_node,
        node_d0130_sapmf05a                 TYPE REF TO if_wd_context_node,
        node_pstap                          TYPE REF TO if_wd_context_node,
        node_info                           TYPE REF TO if_wd_context_node_info,
        ls_fprops                           TYPE wdy_attribute_format_prop.
      node_do_not_change = wd_context->get_child_node( name = wd_this->wdctx_do_not_change ).
      node_d0130_sapmf05a = node_do_not_change->get_child_node( name = wd_this->wdctx_d0130_sapmf05a ).
      node_pstap = node_d0130_sapmf05a->get_child_node( name = wd_this->wdctx_pstap ).
      node_info = node_pstap->get_node_info( ).
      ls_fprops = node_info->get_attribute_format_props( 'VALUE' ).
      ls_fprops-null_as_blank = if_wd_context_node_info=>c_format_null_as_BLANK.
      node_info->set_attribute_format_props(
        name              = 'VALUE'
        format_properties = ls_fprops ).
    Warm Regards,
    Vijay

  • How to keep selection (or select) the row of SORTED ALV table?

    Dear Experts,
    I have WD ALV table with grouped and therefore sorted layout. I know that sorted ALV beahve differently.
    The problem is that if the values in cell is updated (setting attribute of selected element of context node bound to the ALV table), then the whole table is redrawn and selection disappears. It does not happen when layout of ALV is not sorted/grouped.
    I need somehow to select the ALV line again. Method MOV_To of IF_WD_CONTEXT_NODE for some reason is not working in sorted ALV (it selects element on node but not in ALV table). And in ALV Interface controller I also could not find anything usefull.
    Thanks.
    Best regards,
    Dmitry.

    Hallo Dmitry,
    See the sap note :1445428
    [https://service.sap.com/sap/support/notes/1445428|https://service.sap.com/sap/support/notes/1445428]
    Follow this thread which suggest a work around.
    [ALV Table set lead selection while sorting is enable for a column|ALV Table set lead selection while sorting is enable for a column]

  • I am unable to sort multiple columns in a table created in Pages.

    I had been using Appleworks up until I installed Lion and have now switched to iWork. I created a table within a Pages document and am able to sort a single column (using the Table Inspector and choosing Sort from  Edit Rows and Columns) but the Sort option is grayed out when I attempt to sort multiple columns.
    In another post, someone talked about this being a problem if you have merged fields. I do not believe I have done this (to be honest I don't know the function of merging fields).
    This is very frustrating as I was easily able to sort these tables in Appleworks.

    Sharon Anderson wrote:
    Thanks for your quick response! I have been trying that but then found that Numbers would only let me print in landscape view so I had to paste the table back into Pages. Is there a way to print in portrat view (from Numbers?)
    Not so. In the lower left corner of the window, there's an icon that looks like a piece of paper. If you see this:
    you are in Sheet View, or normal, mode. If you see this:
    You are in Print View mode. Now you see the icons for portrait and landscape modes. Click your choice. Then arrange your content to fit the pages as you wish.
    Jerry

  • How to sort a column directly after data is filled into the grid?

    Hello,
    I have a unbound field X, which is filled on fly in the RowLoaded2 column. If I click on the column header, I am able to sort the column.
    I want to sort the column directly, but all attempts have failed.
    I have tried to call in <anchor>_OnUpdate
    <anchor>.bcol.Sort( "X", "ASC") but it does not work as long as the property is not mapped to a Segment field of a bdoc. For this test i just created my property X on the Business Objects behind the tablegrid
    I have used <tablegridcontrol>.sortCol = 2, but it results into a StackOverflowException even for any other column.
    Is there no way to sort the colum in this special kind of situation?
    Regards,
    Andreas

    Hi,
    you have to consider that when loading a tile for the first time always rowloaded2 is fired (several times) and afterwards onload. Maybe rowloaded2 again afterwards. So it should work to sort in onload.
    But when clicking the <back> button in the menue the order of the fired events might be different!
    Do you want to sort by an unbound column which is readonly or is it also editable (see other thread)? In this case things might be much more complicate... Normally another sorting should be done in onsave event but unfortunately you don't save anything as it is unbound...
    Regards,
    Wolfhard

  • Is there any way to do a mass copy and paste of song titles from the "name" column to the "sort name" column? I know it can be done with individual titles but I have over 6,000 titles in my library.

    In iTunes, is there any way to do a mass copy and paste of song titles from the "name" column to the "sort name" column? I know it can be done with individual titles but I have over 6,000 titles in my library.

    Thank you. I have heard of Logic Pro 7, but I have never personally used it. I'm still growing in the world of Composition, and I know that it is something I will be studying in one of my Computer Music classes coming up for my degree. I think it is something I will look into getting once I can justify the price of it. I guess for the time being, I will continue to play and grow in my ability to use and take advantage of GB, and then see what I can do about or with Logic Pro when I'm ready. The thought of spending $1000 for a program is hard to bite, because I've already spent a lot to produce my music, not only electronic music, but also chamber music and so on. I had no idea it would be so expensive to dive deep into the world of composition! lol.
    Finale 2007: $500
    Sibelius 4: $500
    Jam Packs: $400
    Midi Keyboard Interface: $100
    PowerBook: $1700
    Printer for printing scores and analysis: $150
    Logic Pro 7: Oy!
    As you can see it adds up very quickly...that doesn't even include my personal instruments and study materials.
    Thank you for your input, as I haven't really worked much with LP, and therefore didn't know which features are available. I will talk with some of my Composition buddies, and professors and see what they have to say as well, and who knows, I may be able to get the express version through one of them.

  • Web dynpro for abap how to create a customize search help in alv column

       hi:
          Web dynpro for abap how to create a customize search help in alv column and put search help value into alv column?
          Are there specific examples ?
          thanks!!

    HI:
       I want to created a freely programed help which include date&time,and put help value to alv column.
      I have created a freely programed help in web dynpro for abpa application,I refer:
      **************** - WebDynpro for ABAP
      but have a problem!
       If you focus on the the input field in the first row, you get the value help
    However if  I go to the second row and focus on the same input field in this column, I don't get the value help:
    What is a good way to solve similar problems?
    thanks

  • Sort table columns in a table and context created dinamically

    Hello all,
    I have implemented the table sorting several times in another developments, but now I'm facing a problem.
    I have created the table and context node that I need to sort dinamically (before somebody ask me why, I would say that it's the only way to do that for my current project, there was no possibility of doing that in dessign time). I have implemented the table sorting more or less the same way I would do with a table created in dessing time, but when I run my WD the sorting of columns doesn't work.
    In the wdDoModifyView, I have put the following code:
    if(firstTime){
    IWDAction ordenacion     = wdThis.wdCreateAction(IPrivateResultDispGlobalView.WDActionEventHandler.ORDENACION,  null);
    IWDParameters param = ordenacion.getActionParameters();
    param.addParameter("nombreNodo",nombreNodo);
    and in the code of the action
        //@@begin onActionOrdenacion(ServerEvent)
         System.err.println("**** NOMBRE NODO **** "+nombreNodo);
         wdContext.currentContextElement().getTableSorter().sort(wdEvent, wdContext.getChildNode(nombreNodo, IWDNode.LEAD_SELECTION));
        //@@end
    The name of the node ("nombreNodo) it's only correct the first time I click on a column.
    Has anybody implemented the table sorting in a dinamically created table and context node? And how do you do to make it works.
    Thank you very much

    Here is the code
    //Preparamos Navegaciones
    IWDAction abrirProyecto = wdThis.wdCreateAction(IPrivateResultDispGlobalView.WDActionEventHandler.ABRIR_PROYECTO, null);
    IWDAction abrirDisp     = wdThis.wdCreateAction(IPrivateResultDispGlobalView.WDActionEventHandler.ABRIR_DISPONIBLE,  null);
    //IWDAction ordenacion     = wdThis.wdCreateAction(IPrivateResultDispGlobalView.WDActionEventHandler.ORDENACION,  null);
    IWDAction ordenacion=wdThis.wdGetOrdenacionAction();
    IWDParameters param = ordenacion.getActionParameters();
    param.addParameter("nombreNodo",nombreNodo);
    IWDTable table = wdThis.wdGetInformesController().crearTabla(view, nombreNodo, movimientosInfo,new String[]{"Codi Projecte",null,"Nom Projecte", "Import Projecte", "Client", "Increment Disponible futur per facturació no emesa i / o anualitats pendents","Increment Disponible futur per ingressos pendents de cobrar", "Disponible"},new String[]{"10px", null,"10px", "10px","10px","10px","10px","10px"},new IWDAction[]{abrirProyecto,null, null, null, null,null,null,abrirDisp}, -1);
    //ordenar tabla
    wdContext.currentContextElement().setTableSorter(new TableSorter(table, ordenacion,null));
    containerTablasProyecto.addChild(table);
    Edited by: Mireia Romo on May 28, 2009 12:27 PM

  • Pages:  How can I sort one column of words and not have it affect the other columns?

    How can I sort one column of words and not have it affect the other columns?  I have opened the inspector to the edit columns and rows under Table.  It will sort the column, but then it changes the other colums as well.  I know that if I use Numbers, it will work, but I want to know how to do the same thing in Pages.

    Hi Peter,
    Numbers sorts full rows on values in selected column(s). The technique for sorting a single column is essentially the same as Jerry is describing for Pages tables—separate the (data in the) column to be sorted, sort it, return it to the table.
    In Numbers the actual column may be separated from the original table, sorted, then returned. In Pages, the data must be extracted, sorted, then pasted back in, overwriting the unsorted data (if it was left in the original table).
    iWork tables follow a database model in which each row is a Record, and each column holds a Field within the records.
    As evidenced by the current question (and several similar questions arising in the Numbers community) that model doesn't apply to the way some users, especially some who come in from the MS Excel world, use tables.
    With Excels model—islands of data on a single large table, the ability to sort one or a selected few columns of data makes sense. One 'island' may comprise only cells AA21:AH50. Sorting that small 'table' should be possible without disturbing the rest of rows 21-30, which are probably part of one or more other 'data islands' in the sea that is a MS Excel spreadsheet.
    In Numbers, each of those 'islands' would be a separate Table, and that Table would be sortable without disturbing other Tables in the document.
    Regards,
    Barry

  • Numbers Sort function. In Numbers 09 there was 'rearrange' which worked perfectly. New Numbers 13 has Sort by column but I can't get it to work. is there a bug?

    In Numbers 09 there was 'rearrange' which worked perfectly. New Numbers 13 has Sort by column but I can't get it to work. is there a bug?

    Numbers '09 has a Reorganize panel and the top section of that panel is for sorting. Numbers 3 also has the ability to sort and it works.  However, Numbers '09 and Numbers 3 sort differently.
    In Numbers '09, if you had a formula such as =Table 1::A1 and if a sort of Table 1 moved cell A1 to A20, the formula would change to =Table 1::A20. In Numbers 3, the formula would stay =Table1::A1.

Maybe you are looking for

  • Mini display incompatible with older ADC-displays?

    I have no problem connecting my 23" aluminum bezel display in my office to my new 13" MBP, but when I wanted to hook up my older model 20" Cinema Display (plastic grey bezel) at home, the display was not recognized. Does anybody know if this is indee

  • How do I "freeze" the top row

    How do I freeze the top row so that I can see it even if I scroll down many cells?

  • TimeOut in search-help

    Hello, I implemented a new search-help inside the standard VMVA. How can I handle, that the user get an information, if the used selection-parameters are not enough and the system generated an time out. I don´t want to see the dump with time-out. Ins

  • Cover art on nano

    I just uploaded a bunch of CDs and all are fine with the exception of one. The artwork is in my library on each track but just a black square on my nano. I tried deleteing and uploading again. After a final sync I still have the same result. Is ther

  • Frieht G/L accounts

    how can we post frieght into separate G/L accounts instead of stock account