Sort the Valuenode records in table

Hi Experts,
Following is the code I wore to retrive and display Portal roles in a table. The context maintained is as follows and got the results properly. I want to know how to sort the table values by Role_Name?. Could some one help me?
[Value node]      Role_table
[Value Attribute] RoleID
[Value Attribute] Role_Name
[Value Attribute] PCD_Location
//Retrive the roles from the Role factory          
String[] theroles = rolefact.getRolesOfUser(unique_id,true);
for(int i=0; i<theroles.length; i++ )
//Retrive user attributes and add to the context attribute values     
String roleid = rolefact.getRole(theroles<i>).getDisplayName();          
String rolename = rolefact.getRole(theroles<i>).getDescription();
String role_desc = rolefact.getRole(theroles<i>).getUniqueName();
IPrivateUserView.IRole_tableElement rowelement = wdContext.createRole_tableElement();
rowelement.setAttributeValue("RoleID",roleid);
rowelement.setAttributeValue("Role_Name",rolename);
rowelement.setAttributeValue("PCD_Location",role_desc);
//Append the roles obtained and bind to the rolenode
al.add(rowelement);
wdContext.nodeRole_table().bind(al);
Please help me with some code on how to sort the value node table?. I promise to award the points for the right solution. I appreciate coding help.
Thank you
Regards
Maruti

Hi Maruti,
1. Get the size of the node, save it in a variable say <b>si</b>
int si = wdContext.nodeRole_table().size();
2. Iterate as follows
for(int i=0;i<si;i++)   
     for(int j=i+1;j<si;j++)
         if(wdContext.nodeRole_table().getRole_tableElementAt(i).getAttributeAsText("Role_Name").compareToIgnoreCase(wdContext.nodeRole_table().getRole_tableElementAt(j).getAttributeAsText("Role_Name"))<0)
         wdContext.nodeRole_table().swapElements(i,j);
Regards,
Mathan MP

Similar Messages

  • How  to  copy  the  table1selected  records into table 2 in webdynpro java.

    Hi 
           how  to  copy  the  table1selected  records into table 2 in webdynpro java.
    venkat
    Edited by: venkatpvr on Sep 23, 2011 11:53 AM

    Hi Venkat,
    You have 2 Value Nodes one for Table1 and second for Table2.
    Table1 node having one more Value Attribute i.e check Box data type is Boolean. Now you are requirement are select records from Table1 Node and click on One Method that records will moves to Second Table2 Node.
    Create One Method for getting the Records from 1-Table to 2-Table
    CopytoTable2 ()
    In this method you have to write code like this
    If (wdContext.nodeTable1.Checkbox(true))
    If(1. Check the Table1 Value Node Size()>0)
    Get the Table1 records and set to table2 Value node.
    Else
    Please select check box// Error message
    Hope this helps!!
    Regards
    Vijay K

  • How to sort the new records when you input them in a Forms bloc?

    Hi,
    I have a multi-record data block, how can I do to sort the records in this block when you enter some new records? for instance, you have a table(emp), 3 coloumns(empid, empname, deptno). when you enter new records, how can you do to make records order by deptno? not in quiry status.
    Thanks. Please help me!

    I think Steve has answered your question and I doubt that what Frank is suggesting is what you are actually trying to do.
    However,
    from the top of my head I don't know if you can set the order by clause on a datablock dynamically <<-Yes you can set it with set_block_property. You don't really want to put it in the where clause because if the user enters query criteria in database fields, they will get appended after the order by and the query will fail.

  • How to save the selected records from Table control in dialog programming

    Hiiiiiiii Every1
    Actually the problem is like this:-
    I have to select some records from table control and then want to save the selected records in DB table.
    Example
    I have some rows having inforamtion bout employees...
    Now what i want is that when i click on 'SAVE' button then these selected rows should be moved into DB table.
    Sachin Dhingra

    see below example, I have added INSERT option after DELETE option.
    REPORT demo_dynpro_tabcont_loop_at.
    CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
    DATA cols LIKE LINE OF flights-cols.
    DATA: ok_code TYPE sy-ucomm,
          save_ok TYPE sy-ucomm.
    DATA: itab TYPE TABLE OF demo_conn.
    TABLES demo_conn.
    SELECT * FROM spfli INTO TABLE itab.
    LOOP AT flights-cols INTO cols WHERE index GT 2.
      cols-screen-input = '0'.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
    ENDMODULE.
    MODULE cancel INPUT.
      LEAVE PROGRAM.
    ENDMODULE.
    MODULE read_table_control INPUT.
      MODIFY itab FROM demo_conn INDEX flights-current_line.
    ENDMODULE.
    MODULE user_command_0100 INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'TOGGLE'.
          LOOP AT flights-cols INTO cols WHERE index GT 2.
            IF  cols-screen-input = '0'.
              cols-screen-input = '1'.
            ELSEIF  cols-screen-input = '1'.
              cols-screen-input = '0'.
            ENDIF.
            MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDLOOP.
        WHEN 'SORT_UP'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) ASCENDING.
            cols-selected = ' '.
            MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'SORT_DOWN'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) DESCENDING.
            cols-selected = ' '.
            MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'DELETE'.
          READ TABLE flights-cols INTO cols WITH KEY screen-input = '1'.
          IF sy-subrc = 0.
            LOOP AT itab INTO demo_conn WHERE mark = 'X'.
              DELETE itab.
            ENDLOOP.
          ENDIF.
        WHEN 'INSERT'.
          READ TABLE flights-cols INTO cols WITH KEY screen-input = '1'.
          IF sy-subrc = 0.
            LOOP AT itab INTO demo_conn WHERE mark = 'X'.
              itab1 = itab.
              modify itab1.
            ENDLOOP.
          ENDIF.
          if not itab1 is initial.
            INSERT dbtab FROM TABLE itab1.
          endif.
      ENDCASE.
    ENDMODULE.

  • Sort the details record

    Hey,
    I got a problem...
    I have a form which has master (say A)and detail (say B) table information displayed. When I query the master the corresponding details records are also displayed in the form. But the details records which are fetched automatically in the form are NOT SORTED out according to my criteria.
    Can anybody tell me how to do this???
    -Ganesh

    Ganesh,
    how and where do you set this criteria? Are you setting the order by property on the block?
    Frank

  • Problem in modifying the existing record in table control

    Hi Experts,
    I have one table control.I have entered one record and save it.When I am modifying the same record a duplicate record is created.I need if I modify the same record that record should only modify.How to delete the duplicate record.

    Hi,
    In Flow logic.
    LOOP .                        
      MODULE tbc_modify ON CHAIN-REQUEST.
      MODULE tbc_mark.     
    ENDLOOP.    
    In module.
    MODULE tbc_modify INPUT.
      MODIFY t_data
        FROM fs_data
       INDEX tbc-current_line.
      IF sy-subrc NE 0.
        APPEND fs_data TO t_data.
      ENDIF.                              
    ENDMODULE.                            
    MODULE tbc_mark INPUT.
      DATA: tbc_wa2 LIKE LINE OF t_data.
      IF tbc-line_sel_mode = 1
      AND fs_data-mark = 'X'.
        LOOP AT t_data  INTO tbc_wa2
         WHERE mark = 'X'.
          tbc_wa2-mark = ''.
          MODIFY t_data
            FROM tbc_wa2
            TRANSPORTING mark.
        ENDLOOP.                          .
      ENDIF.                             
      MODIFY t_data  FROM fs_data
        INDEX tbc-current_line
        TRANSPORTING mark.      
    ENDMODULE.
    Edited by: sapabap403 on Aug 31, 2011 9:29 AM

  • How to lock the perticular record in table with some of fields

    Hi,
    I have one Doubt please clarify me.
    How to lock the record in table with perticular fields combination please give me example of code.
    Thanks,
    Hari.

    Hi,
    IT LIKE this....
    This is the function mode that you have to create for locking the contents of you internal table.
      CALL FUNCTION 'ENQUEUE_EZHFINDID'
       EXPORTING
         mode_zhfindid        = 'E'
         mandt                = sy-mandt
         ownid                = w_display-ownid
      X_OWNID              = ' '
      _SCOPE               = '2'
      _WAIT                = ' '
      _COLLECT             = ' '
       EXCEPTIONS
         foreign_lock         = 1
         system_failure       = 2
         OTHERS               = 3.
      CASE sy-subrc.
        WHEN 1.
          w_flag_lock = c_x.
         CLEAR w_okflag.
          MESSAGE e265 WITH w_display-ownnum.
      ENDCASE.
    Jayant Sahu.

  • Sort the columns of a table

    Hi,
    There is a table with lot of data. I want to change the order in which the columns are displayed when the table is queries. Is there any way or i just have to drop the table and recreate again.
    Have a nice day.
    Thank you
    PK

    Hi,
    Like user637951 said, you only need to change the order in your query. Example:
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL> desc employees;
    Name           Type         Nullable Default Comments                                                                                                                                                                                 
    EMPLOYEE_ID    NUMBER(6)                     Primary key of employees table.                                                                                                                                                          
    FIRST_NAME     VARCHAR2(20) Y                First name of the employee. A not null column.                                                                                                                                           
    LAST_NAME      VARCHAR2(25)                  Last name of the employee. A not null column.                                                                                                                                            
    EMAIL          VARCHAR2(25)                  Email id of the employee                                                                                                                                                                 
    PHONE_NUMBER   VARCHAR2(20) Y                Phone number of the employee; includes country code and area code                                                                                                                        
    HIRE_DATE      DATE                          Date when the employee started on this job. A not null column.                                                                                                                           
    JOB_ID         VARCHAR2(10)                  Current job of the employee; foreign key to job_id column of the
    jobs table. A not null column.                                                                                         
    SALARY         NUMBER(8,2)  Y                Monthly salary of the employee. Must be greater
    than zero (enforced by constraint emp_salary_min)                                                                                       
    COMMISSION_PCT NUMBER(2,2)  Y                Commission percentage of the employee; Only employees in sales
    department elgible for commission percentage                                                                             
    MANAGER_ID     NUMBER(6)    Y                Manager id of the employee; has same domain as manager_id in
    departments table. Foreign key to employee_id column of employees table.
    (useful for reflexive joins and CONNECT BY query)
    DEPARTMENT_ID  NUMBER(4)    Y                Department id where employee works; foreign key to department_id
    column of the departments table                                                                                        
    SQL> select e.employee_id, e.first_name, e.last_name from employees e where e.employee_id = 100;
    EMPLOYEE_ID FIRST_NAME           LAST_NAME
            100 Steven               King
    SQL> select e.first_name, e.last_name, e.employee_id from employees e where e.employee_id = 100;
    FIRST_NAME           LAST_NAME                 EMPLOYEE_ID
    Steven               King                              100
    SQL> Regards,

  • Query to print the max value of time of the latest record from table

    hi
    i wrote this query
    which should return max fx_time of the latest or current value of fx_date
    plz help
    this wuery is giving current date fx_date but with all values not the max value of fx_time.
    select FX_DATE, FX_TIME,FROM_CURRENCY, TO_CURRENCY, ASK_RATE, BID_RATE,
    time_stamp, source,
    DESCRIPTION, FX_TYPE, OVERRIDDEN_RATE, OVERRIDDEN_BY, OVERRIDDEN_DATE ,
    ASK_RATE_INVERSE, BID_RATE_INVERSE, PX_LAST, PX_MID, PX_OPEN, PX_HIGH,
    PX_LOW,NY_TIME_OF_LAST_PRICE_UPDATE,
    DATE_OF_LAST_UPDATE, PX_BID_AM, PX_ASK_AM, PX_BID_PM, PX_ASK_PM, PX_CLOSE_1D,
    CHG_NET_1D,
    CHG_PCT_1D, PRICING_SOURCE, PX_BID_1M, PX_ASK_1M, PX_BID_1YR, PX_ASK_1YR,
    PX_CLOSE_MTD,
    PX_CLOSE_YTD, FXOPT_COMMODITY_CCY, FXOPT_SPOT_FXRATE, SPOT_RT_USD_FLAG,
    PRIOR_CLOSE_BID,
    PRIOR_CLOSE_MID, PRIOR_CLOSE_ASK from CURRENCY_EXCHANGE_TXN
    WHERE
    source='BLOOMBERG'
    AND FX_DATE=
    (select max(fx_date) JIM from CURRENCY_EXCHANGE_TXN
    ,(select max(fx_time) TIM from CURRENCY_EXCHANGE_TXN GROUP BY FX_TIME )
    what change should i do

    Hi,
    Try this:
    select FX_DATE, FX_TIME,FROM_CURRENCY, TO_CURRENCY, ASK_RATE, BID_RATE,
    time_stamp, source,
    DESCRIPTION, FX_TYPE, OVERRIDDEN_RATE, OVERRIDDEN_BY, OVERRIDDEN_DATE ,
    ASK_RATE_INVERSE, BID_RATE_INVERSE, PX_LAST, PX_MID, PX_OPEN, PX_HIGH,
    PX_LOW,NY_TIME_OF_LAST_PRICE_UPDATE,
    DATE_OF_LAST_UPDATE, PX_BID_AM, PX_ASK_AM, PX_BID_PM, PX_ASK_PM, PX_CLOSE_1D,
    CHG_NET_1D,
    CHG_PCT_1D, PRICING_SOURCE, PX_BID_1M, PX_ASK_1M, PX_BID_1YR, PX_ASK_1YR,
    PX_CLOSE_MTD,
    PX_CLOSE_YTD, FXOPT_COMMODITY_CCY, FXOPT_SPOT_FXRATE, SPOT_RT_USD_FLAG,
    PRIOR_CLOSE_BID,
    PRIOR_CLOSE_MID, PRIOR_CLOSE_ASK from CURRENCY_EXCHANGE_TXN
    WHERE
    source='BLOOMBERG'
    AND FX_DATE=
    (select max(fx_date) JIM from CURRENCY_EXCHANGE_TXN
    FX_TIME )
    [PRE]
    Please always use [ PRE ]  and [ / PRE ] tags when ever posting any code.
    Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Sorting based on non-base table columns

    I have a form block based on X table. There are also some columns from Y table in the same block and the tables X and Y are joined through the appropriate columns. I want to sort the queried record in the block ( based on table X ) based on two columns that are present in the Y table. How do I do this? Any help would be highly appreciated. Ofcourse! we can create a view and achieve that. But I don't want to create a view. Also I can use select statement in the order by column. But it works if I select one column. But when I select two columns it says too many value. Any solutions

    why dont u create a function
    and sort by the returning values ?

  • Duplicate records in TABLE CONTROL

    Hi folks,
    i am doing a module pool where my internal table (itab) data is comming to table ontrol(ctrl).then i need to select one record in table control & then i press REFRESH push button.
    after putting the refresh button, some new records are comming to that same internal table.then i need to display the modified internal table (some new records are added) data in the table control.
    The modified internal table data is comming to the table control but to the last of table control, some records are repeating.
    before comming to table control, i checked the modified itab. it contains correct data.i.e it contains 15 records.(previously i have 5 records.after REFRESH button 10 more records are added.). but when this table is comming to table control, it contains some 100 record.i should get only 15 record.
    why these records r repeting. how to delete the duplicate records from table control?
    plz suggest me where i am doing mistake.
    correct answer will be rewarded
    Thanks & Regards

    Hi ,
    Thanks for ur help. but i should not refresh the internal table  as some records r already present.after putting the REFRESH button, some new records r appending to this existing table.then i am going to display the previous records & the new records as well.
    i checked the internal table after modification.it contains actual number of records. but after comming to table control , more records r comming.
    is this the problem with scrolling or waht?
    plz suggest where i am doing mistake.i am giving my coding below.
    PROCESS BEFORE OUTPUT.
    MODULE STATUS_0200.
    module tc_shelf_change_tc_attr.
    loop at object_tab1
           with control tablctrl
           cursor tablctrl-current_line.
        module tc_shelf_get_lines.
      endloop.
    PROCESS AFTER INPUT.
    module set_exit AT EXIT-COMMAND.
       loop at object_tab1.
             chain.
              field: object_tab1-prueflos,
                     object_tab1-matnr.
               module shelf_modify on chain-request.
             endchain.
            field object_tab1-idx
             module shelf_mark on request.
                   endloop.
    module shelf_user_command.
    module user_command_0200.
    ***INCLUDE Y_RQEEAL10_STATUS_0200O01 .
    *&      Module  STATUS_0200  OUTPUT
          text
    MODULE STATUS_0200 OUTPUT.
      SET PF-STATUS 'MAIN'.
    SET TITLEBAR 'xxx'.
    ENDMODULE.                 " STATUS_0200  OUTPUT
    *&      Module  tc_shelf_change_tc_attr  OUTPUT
          text
    MODULE tc_shelf_change_tc_attr OUTPUT.
    delete adjacent duplicates from object_tab1 comparing prueflos matnr.
    describe table object_tab1 lines tablctrl-lines.
    ENDMODULE.                 " tc_shelf_change_tc_attr  OUTPUT
    *&      Module  tc_shelf_get_lines  OUTPUT
          text
    MODULE tc_shelf_get_lines OUTPUT.
    data:  g_tc_shelf_lines  like sy-loopc.
    if tablctrl-current_line > tablctrl-lines.
    stop.
    endif.
    g_tc_tablctrl_lines = sy-loopc.
    *refresh control tablctrl from screen 0200.
    ENDMODULE.                 " tc_shelf_get_lines  OUTPUT
    ***INCLUDE Y_RQEEAL10_SHELF_MODIFYI01 .
    *&      Module  shelf_modify  INPUT
          text
    MODULE shelf_modify INPUT.
    modify object_tab1
        index tablctrl-current_line.
    ENDMODULE.                 " shelf_modify  INPUT
    *&      Module  set_exit  INPUT
          text
    module set_exit INPUT.
    leave program.
    endmodule.                 " set_exit  INPUT
    *&      Module  shelf_mark  INPUT
          text
    MODULE shelf_mark INPUT.
    data: g_shelf_wa2 like line of object_tab1.
      if tablctrl-line_sel_mode = 1
      and object_tab1-idx = 'X'.
        loop at object_tab1 into g_shelf_wa2
          where idx = 'X'.
          g_shelf_wa2-idx = ''.
          modify object_tab1
            from g_shelf_wa2
            transporting idx.
        endloop.
      endif.
      modify object_tab1
        index tablctrl-current_line
        transporting idx plnty plnnr plnal.
    ENDMODULE.                 " shelf_mark  INPUT
    *&      Module  shelf_user_command  INPUT
          text
    MODULE shelf_user_command INPUT.
    ok_code = sy-ucomm.
      perform user_ok_tc using    'TABLCTRL'
                                  'OBJECT_TAB1'
                         changing ok_code.
      sy-ucomm = ok_code.
    ENDMODULE.                 " shelf_user_command  INPUT
    *&      Module  user_command_0100  INPUT
          text
    MODULE user_command_0200 INPUT.
    data:v_line(3).
    case OK_CODE.
    when 'LAST'.
    read table object_tab1 with key idx = 'X'.
    if sy-subrc = 0.
    select * from qals
                          where enstehdat <= object_tab1-enstehdat
                          and   plnty ne space
                          and   plnnr ne space
                          and   plnal ne space.
    if sy-dbcnt > 0.
    if qals-enstehdat = object_tab1-enstehdat.
       check qals-entstezeit < object_tab1-entstezeit.
       move-corresponding qals to object_tab2.
       append object_tab2.
       else.
       move-corresponding qals to object_tab2.
       append object_tab2.
       endif.
         endif.
            endselect.
       sort object_tab2 by enstehdat entstezeit descending.
    loop at object_tab2 to 25.
      if not object_tab2-prueflos is initial.
    append object_tab2 to object_tab1.
      endif.
      clear object_tab2.
    endloop.
      endif.
    when 'SAVE'.
    loop at object_tab1 where idx = 'X'.
      if ( not object_tab1-plnty is initial and
                    not object_tab1-plnnr is initial and
                               not object_tab1-plnal is initial ).
       select single * from qals into corresponding fields of wa_qals
       where prueflos = object_tab1-prueflos.
          if sy-subrc = 0.
           wa_qals-plnty = object_tab1-plnty.
           wa_qals-plnnr = object_tab1-plnnr.
           wa_qals-plnal = object_tab1-plnal.
    update qals from wa_qals.
      if sy-subrc <> 0.
    Message E001 with 'plan is not assigned to lot in sap(updation)'.
    else.
    v_line = tablctrl-current_line - ( tablctrl-current_line - 1 ).
    delete object_tab1.
    endif.
       endif.
          endif.
               endloop.
    when 'BACK'.
    leave program.
    when 'NEXT'.
    call screen 300.
    ENDCASE.
    ***INCLUDE Y_RQEEAL10_USER_OK_TCF01 .
    *&      Form  user_ok_tc
          text
         -->P_0078   text
         -->P_0079   text
         <--P_OK_CODE  text
    form user_ok_tc  using    p_tc_name type dynfnam
                              p_table_name
                     changing p_ok_code like sy-ucomm.
       data: l_ok              type sy-ucomm,
             l_offset          type i.
       search p_ok_code for p_tc_name.
       if sy-subrc <> 0.
         exit.
       endif.
       l_offset = strlen( p_tc_name ) + 1.
       l_ok = p_ok_code+l_offset.
       case l_ok.
         when 'P--' or                     "top of list
              'P-'  or                     "previous page
              'P+'  or                     "next page
              'P++'.                       "bottom of list
           perform compute_scrolling_in_tc using p_tc_name
                                                 l_ok.
           clear p_ok_code.
       endcase.
    endform.                    " user_ok_tc
    *&      Form  compute_scrolling_in_tc
          text
         -->P_P_TC_NAME  text
         -->P_L_OK  text
    form compute_scrolling_in_tc using    p_tc_name
                                           p_ok_code.
       data l_tc_new_top_line     type i.
       data l_tc_name             like feld-name.
       data l_tc_lines_name       like feld-name.
       data l_tc_field_name       like feld-name.
       field-symbols <tc>         type cxtab_control.
       field-symbols <lines>      type i.
       assign (p_tc_name) to <tc>.
       concatenate 'G_' p_tc_name '_LINES' into l_tc_lines_name.
       assign (l_tc_lines_name) to <lines>.
       if <tc>-lines = 0.
         l_tc_new_top_line = 1.
       else.
         call function 'SCROLLING_IN_TABLE'
           exporting
             entry_act      = <tc>-top_line
             entry_from     = 1
             entry_to       = <tc>-lines
             last_page_full = 'X'
             loops          = <lines>
             ok_code        = p_ok_code
             overlapping    = 'X'
           importing
             entry_new      = l_tc_new_top_line
           exceptions
             others         = 0.
       endif.
       get cursor field l_tc_field_name
                  area  l_tc_name.
       if syst-subrc = 0.
         if l_tc_name = p_tc_name.
           set cursor field l_tc_field_name line 1.
         endif.
       endif.
       <tc>-top_line = l_tc_new_top_line.
    endform.                              " COMPUTE_SCROLLING_IN_TC
    Thanks

  • BDC for existing record in table control

    Hi,
    I have a requirement to change existing records in table control through BDC. Is there any way I can choose the respective record from Table Control through BDC dynamically.
    Regards
    Akash

    /J4I/015PER, this transaction is used for adding permits to Operation in WEC. It has list of operations in Table Control. Permit can be added for choosing the operation from table control.
    Our custom program is designed to add permits for the operation. So if I have to use the above transaction for adding permits, then first I have to choose the correct operation from the table control and then add permit.

  • How to Sort single column in webdynpro table

    Hi all
    I have requirement as follows.
    i have webdynpro table with the following columns like Date,firstname,lastname,address etc.
    now when i run the the application the table is populating the data at runtime that is fine.
    i need as soon as table is loaded , Date field in the table should be displayed the values in the decending order...i have the requirement as follows...
    how to sort the single column in table ...by default the values of the column displayed with decending order as soon as table displays at runtime....i dont want to click any button specific button to do the sort for that column
    Regards
    bindu

    Hi, I solved the same problem by modifying the sort() method in the default TableSorter class so that it takes a column id and direction rather than an event.
    I assume you have read the TableSorter tutorial.
    Like this. (This was done on nw ce 7.1 btw but may work on older versions as well.
    Oh and then you just call the sort method right after you have made the request
    //Code that goes into controller/view to execute sorting
    wdContext.currentContextElement().getPensionplanTableSorter().sort("MyColumnId", "Up", wdContext.nodePensionPlan());
    //Part of TableSorter.java
    //The original method that needs an event. Now it just calls the new method
    public void sort(IWDCustomEvent wdEvent, IWDNode dataSource) {
         // find the things we need
         String columnId = wdEvent.getString("selectedColumn");
         String direction = wdEvent.getString("sortDirection");
         sort(columnId, direction, dataSource);
    //This is the new method.
    public void sort(String columnId, String direction, IWDNode dataSource) {
         if (columnId == null || direction == null ) {
              return;
         IWDTableColumn column = (IWDTableColumn) table.getView().getElement(columnId);
         NodeElementByAttributeComparator elementComparator =
    (NodeElementByAttributeComparator) comparatorForColumn.get(column);
         if (elementComparator == null){
         //not a sortable column
              column.setSortState(WDTableColumnSortDirection.NOT_SORTABLE);
              return;
         // sorting
         elementComparator.setSortDirection(WDTableColumnSortDirection.valueOf(direction));
         dataSource.sortElements(elementComparator);

  • Unable to sort the records of a table

    Hi Experts,
    I have populated one z table with records. The table coloumns are as below:
    Mandt
    Pernr
    Personnel Area
    Total Points
    Rank
    I have to sort the table records in descending order of Total Points. In many cases there will be same total points for many records. In such cases we have to arrange records in following fashion:
    If more than 1 person have same total points then person having more years of service will have higher rank
    If more than 1 person have same total points and same years of service then older people (date of birth) will have higher rank.
    I have written following program. It is not working. Please help me. If you have some ready made code, please share with me.
    Regards,
    Gary
    IF NOT itab_prio[] IS INITIAL.
          CLEAR v_index.
          v_index = 1.
          SORT itab_prio BY z_prio_pts DESCENDING .
          itab_rank[] = itab_prio[].
          LOOP AT itab_prio.
    *---Check eligibility.
            CALL FUNCTION 'zmy_prg_CHECK_ELIGIBILITY'
              EXPORTING
                pernr  = itab_prio-z_pernr
              IMPORTING
                return = return.
            IF return-type = 'E'.
              itab_prio-z_prio_pts = 0.
              itab_prio-z_prio = 0.
              MODIFY itab_prio TRANSPORTING z_prio_pts z_prio.
            ELSE.
              LOOP AT itab_rank WHERE z_prio_pts = itab_prio-z_prio_pts
                                AND   z_pernr    NE itab_prio-z_pernr.
    *---Get Hiring date for same rank.
                CALL FUNCTION 'zmy_prg_GET_EMP_HIRING_DATE'
                  EXPORTING
                    pernr       = itab_rank-z_pernr
                  IMPORTING
                    hiring_date = hire_new.
    *---Get Hiring date of update emp.
                CALL FUNCTION 'zmy_prg_GET_EMP_HIRING_DATE'
                  EXPORTING
                    pernr       = itab_prio-z_pernr
                  IMPORTING
                    hiring_date = hire_old.
                IF hire_old = hire_new.
    *---Check for Birth date of both employees.
                  READ TABLE it_date WITH KEY  pernr = itab_rank-z_pernr.
                  IF sy-subrc = 0.
                    hijri_new = it_date-zzhdob.
                  ENDIF.
                  READ TABLE it_date WITH KEY  pernr = itab_prio-z_pernr.
                  IF sy-subrc = 0.
                    hijri_old = it_date-zzhdob.
                  ENDIF.
                  IF hijri_old > hijri_new.
                    flag = 'X'.
                  ENDIF.
                ENDIF.
              ENDLOOP.
              IF flag NE 'X'.
                itab_prio-z_prio = v_index.
                v_index = v_index + 1.
                MODIFY itab_prio TRANSPORTING z_prio.
              ELSE.
                itab_prio-z_prio = v_index.
                v_index = v_index + 1.
                MODIFY itab_prio TRANSPORTING z_prio.
              ENDIF.
            ENDIF.
            CLEAR : flag , return.
          ENDLOOP.
          MODIFY zhop_priority_pt FROM TABLE itab_prio.
          COMMIT WORK.
          IF sy-subrc = 0.
            MESSAGE i000(zz) WITH 'sucessfully generated'.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDFORM.
    Please use code tags to format your code
    Edited by: Rob Burbank on Sep 29, 2010 1:59 PM

    Gary,
    Firstly, to make things easier, I suggest you add service and age columns to your internal table.
    Mandt
    Pernr
    Personnel Area
    Total Points
    Service
    Age
    Rank
    Does your internal table itab_prio contain large number of rows? Is the code that determines service and age performance intensive? If the answer is 'NO', then I suggest you populate service and age for every row and sort. This will make the logic simple and easy to maintain.
    If you must query service and age only when there is a conflict, then following logic should help.
    - itab_prio_copy[] = itab_prio[].
    - Loop at itab_prio.
    -   l_next_row = sy-tabix + 1.
    -   read table itab_prio_copy index l_next_row.
    -   are points same?
    -     get service for both the employees.
    -     is the service same for both?
    -       get age for both.
    -    rank accordingly
    - endloop.
    I know I have skipped a lot of gotcha points. For example, how to handle the last row, how to update the rank to the next row, etc. I am sure you can figure that out.
    Good luck.

  • Want to sort the records based on non-base table item

    I have a multi-record block and I am trying to sort the data based on nbt item
    I have a table called X which has x_type,x_code fields.
    The table on which the block is created is Y. the table Y has x_type and y_desc as its fields
    form layout is like below .the x_type is key field on which I have to query the records
    and x_code is a non-base item in the form.I want to sort the records by X_code.
    x_code y_desc
    A     xyz
    c par
    B     lmn
    my pre-query has this code
    select x_type from y
    where
    x_type := x_type;
    post-query has this code
    select x_code from x
    where x_type = :x_type;     
    It works fine in Enter-Queryand execute query mode. but when I am sorting the records on
    nbt item x_code by SET-BLOCK-PROPERTY it doesn't do any thing

    Hi Tony ,
    I have created a function and in Pre-Query & have add this
    SET_BLOCK_PROPERTY('b1', ORDER_BY, 'fn_get_code(x_type)');
    and the function created is as below
    Function fn_get_code (p_x_type in varchar2) return varchar2 is
    v_code varchar2(40);
    begin
    select x_code into v_code
    from X, Y
    where X.x_type = Y.x_type
    and y.x_type = p_x_type
    return v_code;
    end;
    when I run the form and execute query it comes up with the error message
    FRM-40505 and when I pressed display error it shows
    SQL Statement error:
    SELECT ROWID,X_TYPE,X_CODE
    FROM Y order by fn_get_code(x_type)
    Error:
    "ORA-00904: "FN_GET_code": invalid identifier"
    Is it that I need to create a function on the database?. As I have created function
    in program unit section

Maybe you are looking for