Sorting table in a jsp

Hello All,
I want to sort a result set by column name...I'm using MVC pattern ....so I have an if clause to decide the sorting order as:
<c:if test="${sort == asc}">
Student
</c:if>
<c:if test="${sort == desc}">
Student
</c:if>
I'm using a method in my action which sorts the given list ...so my question is how can i save the resultant List to be sorted ...if I put in request ...it can be displayed only one time and can i keep that in session....or is there any other better way to do this....
Thanks,
Maithri

The JSP generates HTML that is loaded into the browser. Are you asking whether something can be done in that HTML to put information into the next request?
Yes, it can. You could put a copy of the entire table into the next request by making it a whole lot of hidden parameters for the "Controller?sort=asc" URL. But now you are out into the realm of really stupid solutions, so don't do that.
The best solutions are:
1. Sort the data on the client using Javascript.
2. Store the data in the user's session and sort it on the server.
But you have already been told this several times.

Similar Messages

  • Sorted Table - tabix issue

    All,
    I have the following code While executing system is pointing to sy-tabix, but the data I am getting in the READ statement is from last record in the internal table
    report  z_9699_30.
    tables : eket.
    types : begin of ty_eket.
            include structure eket.
    types:  end of ty_eket.
    data: wa_eket                 type ty_eket.
    data: it_eket                 like sorted table of wa_eket
                                  with unique key primary_key
                                  components ebeln ebelp etenr
                                  with non-unique sorted key secondary_key
                                  components ebeln ebelp.
    parameters: p_ebeln like eket-ebeln.
    parameters: p_ebelp like eket-ebelp.
    select * from eket into table it_eket
          where ebeln eq p_ebeln.
          read table it_eket into wa_eket with table key secondary_key
                   components ebeln  = p_ebeln
                              ebelp  = p_ebelp.
    Please copy and execute this by giving EBELN and EBELP from EKET
    Please make sure while selecting from EKET please select data of multiple records available for same EBELP ie llike
    Here below PO # 4500000003 and for Item # 00030 is have multiple records
    Here in selection screen by giving PO # as 4500000003 (EBELN) Item # as 00030 (EBELP) , then in the above READ statement system giving SY-TABIX as 3 but if you see the WA_EKET-ETENR is showing 2 instead of 1. This is where is the issue is
    EBELN
    EBELP
    ETENR
    Header 4
    4500000003
    00010
    1
    4500000003
    00020
    1
    4500000003
    00030
    1
    4500000003
    00030
    2

    Now execute some
    MOVE sy_tabix TO lv_index.
    READ TABLE it_eket INTO wa_eket
          INDEX lv_index USING KEY secondary_key.
    BREAK-POINT.
    READ TABLE it_eket INTO wa_eket
          INDEX lv_index USING KEY primary_key.
    BREAK-POINT.
    and conclude yourself on the meaning of life index with two different keys defined...
    Regards,
    Raymond
    PS: Reference in online help for sy-tabix now
    Note that the sy-tabix system field is populated by the assigned secondary index, if sorted secondary keys are used. If this value is used for the subsequent index access to the internal table, the same table index must be explicitly used here. If used implicitly, the value would be interpreted as a primary index.

  • Error when inserting or changing in a sorted table

    Hi Experts,
    When i am executing a webdynpro application it says Error when inserting or changing in a sorted table. Can any one help for this.
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: GET_CATEGORY_LIST of program /1BCWDY/F9XHYWN4WKNMG4CDUGA8==CP
    Method: IF_COMPONENTCONTROLLER~GET_CATEGORY_LIST of program /1BCWDY/F9XHYWN4WKNMG4CDUGA8==CP
    Method: WDDOMODIFYVIEW of program /1BCWDY/F9XHYWN4WKNMG4CDUGA8==CP
    Method: IF_WDR_VIEW_DELEGATE~WD_DO_MODIFY_VIEW of program /1BCWDY/F9XHYWN4WKNMG4CDUGA8==CP
    Method: DO_MODIFY_VIEW of program CL_WDR_DELEGATING_VIEW========CP
    Method: MODIFY_VIEW of program CL_WDR_VIEW===================CP
    Method: DO_MODIFY_VIEW of program CL_WDR_CLIENT_COMPONENT=======CP
    Method: DO_MODIFY_VIEW of program CL_WDR_WINDOW_PHASE_MODEL=====CP
    Method: PROCESS_REQUEST of program CL_WDR_WINDOW_PHASE_MODEL=====CP
    Method: PROCESS_REQUEST of program CL_WDR_WINDOW=================CP
    in ST22
    Object Definition
      DATA: lo_node                   TYPE REF TO if_wd_context_node,
            lo_node_info              TYPE REF TO if_wd_context_node_info,
            lo_element                TYPE REF TO if_wd_context_element.
    Additional Data declarations
      DATA: lv_key TYPE string.
    Get context node.
      lo_node = wd_context->get_child_node( name = 'DROPDOWNLISTS' ).
      lo_node_info = lo_node->get_node_info( ).
    Call method to fetch the categories.
      CALL METHOD cl_hap_wd_start_page_ui=>category_get_list
        EXPORTING
          add_on_application = add_on_application
        IMPORTING
          t_categories       = lt_categories.
    Append Default selection entry 'All'.
      lw_category-category_id = '00000000'.
      lw_category-category_name = 'All'.
      APPEND lw_category TO lt_categories.
    Sort table after appending the new entry.
      SORT lt_categories ASCENDING.
    Loop through the category list and populate key(category_id) value(category_name) pair for
      LOOP AT lt_categories INTO lw_category.
        lw_key_value-key = lw_category-category_id.
      625     lw_key_value-value = lw_category-category_name.
    >>>>>     APPEND lw_key_value TO lt_key_values.------>Here it throws an error
      627     CLEAR: lw_key_value, lw_category.
      628   ENDLOOP.
      629
      630 * Bind the category key-value pair to the context attribute.
      631   CALL METHOD lo_node_info->set_attribute_value_set
      632     EXPORTING
      633       name      = 'CATEGORY_LIST'
      634       value_set = lt_key_values.
      635
      636 * Make the entry 'All' as default selected.
      637   CALL METHOD lo_node->set_attribute
      638     EXPORTING
      639       value = '00000000'
      640       name  = 'CATEGORY_LIST'.
      641
      642 ENDMETHOD.
      643
      644 method GET_EMPLOYEES.
      645

    Hello Durga,
    from the error what I understood is lt_key_values is a sorted table and you are trying append a new line to it. Incase of sorted table you need to use the INSERT statement and not the APPEND statement.
    INSERT lw_key_value INTO table lt_key_values.
    BR, Saravanan

  • Short Dump While Changing Non-KeyField of Sorted Table

    Hello,
    A short dump occurs while trying to change a field of a sorted table item passed as CHANGING parameter.  Are non-key fields in a sorted structure protected? The error message does not explicitely say so. Can anyone link to documentation explaining this behavior? 
    best regards,
    JNN

    You are passing by reference with CHANGING.
    It looks like read-only stuff can't be passed to method CHANGING.
    When I pass a literal or constant, there is a syntax error.
    System could have given you a syntax error instead of dump.
    Have a look at this snippet. Both method calls throw syntax error.
    CLASS mainclass DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS main.
      PRIVATE SECTION.
        CLASS-METHODS passref CHANGING cv_test TYPE i.
    ENDCLASS.                    "mainclass DEFINITION
    CLASS mainclass IMPLEMENTATION.
      METHOD main.
        "pass literal by ref
        passref(
          CHANGING
            cv_test = '2'
        "pass constant by ref
        CONSTANTS lc_test TYPE i VALUE 1.
        passref(
          CHANGING
            cv_test = lc_test
      ENDMETHOD.                    "main
      METHOD passref.
        "nothing
      ENDMETHOD.                    "passref
    ENDCLASS.                    "mainclass IMPLEMENTATION
    START-OF-SELECTION.
      mainclass=>main( ).

  • How to read the data from a sorted table

    Hi all,
    How to read data from the sorted tables. Please provide some examples.
    Thanks and regards,
    Lisa

    You can read like this :
    DATA: BEGIN OF LINE,
    COL1 TYPE I,
    COL2 TYPE I,
    END OF LINE.
    DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
    DO 4 TIMES.
      LINE-COL1 = SY-INDEX.
      LINE-COL2 = SY-INDEX ** 2.
    INSERT LINE INTO TABLE ITAB.
    ENDDO.
    CLEAR LINE.
    READ TABLE ITAB WITH TABLE KEY COL1 = 3
                    INTO LINE TRANSPORTING COL2.
    WRITE:   'SY-SUBRC =', SY-SUBRC,
           / 'SY-TABIX =', SY-TABIX.
    SKIP.
    WRITE: / LINE-COL1, LINE-COL2.

  • Unable to sort table

    Hi all
    I have created an advance table and using multiple selection.I set Sort Allowed property 'Yes' for every column in property inspector.
    But when I clicked on cloumn it throws a warning "The table cannot be sorted because it has pending changes which would be lost." and I am not able to sort table.
    Can somebody give me some suggestions.
    Thanks
    Bhupendra

    I have createed sortable header.I have done this thing many times and it works.But this time only I m facing problem.I am using PPR in this table where I am enabling and disabling the checkbox.
    Please give suggestions if anybody has faced this problem.
    Thanks
    Bhupendra

  • Possible Sequential Read Access for a Sorted Table

    Hi All,
    I have the following warnings in Code inspector check.
    'Possible Sequential Read Access for a Sorted Table'
    Kindly provide me the solution to overcome this warning message.
    This is my code in BAdi : CRM_ORDER_FIELDCHECK , Method : FIELDCHECK
    I am getting the above warning at
      READ TABLE lt_status INTO ls_status WITH KEY status = 'E0001'
                                                   user_stat_proc = 'ZITRHDQT'
                                                   object_type = 'BUS2000114'.
    and at
        MODIFY ct_input_field_names FROM ls_input_field_names
                                    TRANSPORTING changeable
                                    WHERE fieldname NE lv_field.
    Please see the below code .
      DATA : lt_header_guid TYPE crmt_object_guid_tab,
             lt_item_guid TYPE crmt_object_guid_tab,
             lt_order_i     TYPE crmt_orderadm_i_wrkt,
             ls_order_i     LIKE LINE OF lt_order_i,
             lt_status      TYPE crmt_status_wrkt,
             ls_status      LIKE LINE OF lt_status,
             ls_input_field_names  TYPE crmt_input_field_names.
      DATA : lv_header_guid TYPE crmt_fieldcheck_com-guid,
             lv_chng_no   TYPE c VALUE 'A',
             lv_field(10)  TYPE c VALUE 'ACT_STATUS'.
      DATA: lv_status_completed     TYPE crmt_boolean.
    To Get GUID
      IF is_fieldcheck_com-guid IS NOT INITIAL.
        lv_header_guid = is_fieldcheck_com-guid.
      ELSE.
        lv_header_guid = is_fieldcheck_com-ref_guid.
      ENDIF.
      IF is_fieldcheck_com-ref_kind EQ 'A'.
        INSERT lv_header_guid INTO TABLE lt_header_guid.
        ELSE.
          SELECT SINGLE header FROM crmd_orderadm_i INTO lv_header_guid
                                WHERE guid = is_fieldcheck_com-ref_guid.
          INSERT lv_header_guid INTO TABLE lt_header_guid.
      ENDIF.
    *To Get the required details
      CALL FUNCTION 'CRM_ORDER_READ'
        EXPORTING
          it_header_guid       = lt_header_guid
        IMPORTING
          et_status            = lt_status
        EXCEPTIONS
          document_not_found   = 1
          error_occurred       = 2
          document_locked      = 3
          no_change_authority  = 4
          no_display_authority = 5
          no_change_allowed    = 6
          OTHERS               = 7.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      READ TABLE lt_status INTO ls_status WITH KEY status = 'E0001'
                                                   user_stat_proc = 'ZITRHDQT'
                                                   object_type = 'BUS2000114'.
      IF sy-subrc = 0.
        ls_input_field_names-changeable = lv_chng_no.
        MODIFY ct_input_field_names FROM ls_input_field_names
                                    TRANSPORTING changeable
                                    WHERE fieldname NE lv_field.
      ENDIF.
    ENDMETHOD.
    Regards
    Venkat

    Hello Blake,
    Try this:
    READ TABLE lt_action_fld WITH KEY STATUS = '0' BINARY SEARCH.
    wf_index = sy-tabix.
    loop at lt_action_fld from wf_index.
    if lt_action_fld-status ne '0'.
    exit.
    endif.
    delete lt_action_fld index wf_index.
    endloop.
    Let us know, if this helps.
    Rgds,
    Raghu.

  • What's up when you drag and drop a table into a jsp page?

    Hi All,
    I was wondering what's happen in dragging and drop a table into a jsp page. This question because untill yesterday i had an application up and running, with a table displaying a number of rows of the database, and an action associated with an update into a database.
    The action is managed trough JNDI, defined from Preference-Embedded.......
    It was working.
    Then the machine hosting the db changed IP addres. I went into Webcenter Administration console, I've changed the connection string into the jdbc parameters, by updating the new IP address... but it's not working anymore! The log comes out with a big error, but basically it can't connect at the db!
    So, I think there is somewhere some reference to the old db.....where???
    Thanks
    Claudio

    Yes Shay,
    I got this error:
    JBO-29000: Unexpected exception caught: oracle.jbo.JboException, msg=JBO-29000: Unexpected exception caught: oracle.jbo.JboException, msg=JBO-29000: Unexpected exception caught: oracle.jbo.DMLException, msg=JBO-26061: Error while opening JDBC connection.
    in few hours I'll be able to give you the full stack.
    Thanks
    Clauido
    Message was edited by:
    user637862
    Hi Shay,
    Thanks a lot..you were right.
    I've located the ba4j on the webcenter server...and I've noticed that it was with the old address.
    I think it's a bug, cause on the local machine (before to deploy) this file comes with the right address.
    So next time, before to redeploy a new application, I think I'm going to fiscally delete the folder from j2ee folder.
    Thanks again for the help!
    Claudio

  • Sort table of objects by object attribute

    Hi all,
    I would like to write method for sorting table of objects. Sorting will be according selected attribute of object.
    My problem is that when I have dynamic data, I'm not able to access attributes of object. Here is example in code. Problematic lines are commented.
    If you have any idea how to solve it, I will be very happy.
    CLASS lcl_reflection DEFINITION CREATE PUBLIC.
      PUBLIC SECTION.
        CLASS-METHODS: sort_object_table_by_field IMPORTING field_name   TYPE char72
                                                            direction    TYPE c DEFAULT 'A'
                                                  CHANGING  object_table TYPE table.
    ENDCLASS.                    "lcl_reflection DEFINITION
    CLASS lcl_reflection IMPLEMENTATION.
      METHOD sort_object_table_by_field.
        DATA: obj_type_desc   TYPE REF TO cl_abap_refdescr,
              cls_type_desc   TYPE REF TO cl_abap_classdescr,
              tab_type_desc   TYPE REF TO cl_abap_tabledescr,
              elm_type_desc   TYPE REF TO cl_abap_elemdescr,
              struc_type_desc TYPE REF TO cl_abap_structdescr,
              line            TYPE REF TO data,
              tab             TYPE REF TO data,
              object          TYPE REF TO data,
              lt_component TYPE cl_abap_structdescr=>component_table,
              ls_component LIKE LINE OF lt_component.
        FIELD-SYMBOLS: <object> TYPE any,
                       <tab>    TYPE table,
                       <line>   TYPE any,
                       <value>  TYPE any.
        READ TABLE object_table INDEX 1 ASSIGNING <object>.
        cls_type_desc ?= cl_abap_classdescr=>describe_by_object_ref( <object> ).
        elm_type_desc ?= cls_type_desc->get_attribute_type( field_name ).
        obj_type_desc ?= cl_abap_refdescr=>create( cls_type_desc ).
        UNASSIGN <object>.
        ls_component-name = 'key'.
        ls_component-type = elm_type_desc.
        APPEND ls_component TO lt_component.
        ls_component-name = 'object'.
        ls_component-type ?= obj_type_desc.
        APPEND ls_component TO lt_component.
        struc_type_desc ?= cl_abap_structdescr=>create( lt_component ).
        tab_type_desc ?= cl_abap_tabledescr=>create( p_line_type  = struc_type_desc
                                                     p_table_kind = cl_abap_tabledescr=>tablekind_std
                                                     p_unique     = abap_false ).
        REFRESH lt_component.
        CLEAR ls_component.
        CREATE DATA line TYPE HANDLE struc_type_desc.
        CREATE DATA tab TYPE HANDLE tab_type_desc.
        CREATE DATA object TYPE HANDLE obj_type_desc.
        ASSIGN tab->* TO <tab>.
        ASSIGN line->* TO <line>.
        ASSIGN object->* TO <object>.
        LOOP AT object_table REFERENCE INTO object.
          APPEND INITIAL LINE TO <tab> REFERENCE INTO line.
          ASSIGN object->* TO <value>.
          ASSIGN line->* TO <line>.
    *      <line>-key = <value>->(field_name).
    *      <line>-object = object.
        ENDLOOP.
    *    SORT <tab> BY key.
    *    LOOP AT <tab> REFERENCE INTO line.
    *      APPEND INITIAL LINE TO object_table REFERENCE INTO object.
    *      object = line-object.
    *    ENDLOOP.
      ENDMETHOD.                    "sort_object_table_by_field
    ENDCLASS.                    "lcl_reflection IMPLEMENTATION

    Ok guys, it's solved. It was little bit more complicated then I expected. Thanks for you help.
    METHOD sort_object_table_by_field.
        TYPES: t_object TYPE REF TO object.
        DATA: obj_type_desc   TYPE REF TO cl_abap_refdescr,
              cls_type_desc   TYPE REF TO cl_abap_classdescr,
              tab_type_desc   TYPE REF TO cl_abap_tabledescr,
              elm_type_desc   TYPE REF TO cl_abap_elemdescr,
              struc_type_desc TYPE REF TO cl_abap_structdescr,
              r_line          TYPE REF TO data,
              r_tab           TYPE REF TO data,
              r_object        TYPE REF TO data,
              r_obj           TYPE REF TO data,
              lt_component TYPE cl_abap_structdescr=>component_table,
              ls_component LIKE LINE OF lt_component.
        FIELD-SYMBOLS: <object>    TYPE any,
                       <obj>       TYPE REF TO object,
                       <tab>       TYPE table,
                       <line>      TYPE any,
                       <key>       TYPE any,
                       <fs_key>    TYPE any,
                       <fs_object> TYPE any.
        READ TABLE object_table INDEX 1 ASSIGNING <object>.
        cls_type_desc ?= cl_abap_classdescr=>describe_by_object_ref( <object> ).
        elm_type_desc ?= cls_type_desc->get_attribute_type( field_name ).
        obj_type_desc ?= cl_abap_refdescr=>create( cls_type_desc ).
        UNASSIGN <object>.
        ls_component-name = 'key'.
        ls_component-type = elm_type_desc.
        APPEND ls_component TO lt_component.
        ls_component-name = 'object'.
        ls_component-type ?= obj_type_desc.
        APPEND ls_component TO lt_component.
        struc_type_desc ?= cl_abap_structdescr=>create( lt_component ).
        tab_type_desc ?= cl_abap_tabledescr=>create( p_line_type  = struc_type_desc
                                                     p_table_kind = cl_abap_tabledescr=>tablekind_std
                                                     p_unique     = abap_false ).
        REFRESH lt_component.
        CLEAR ls_component.
        CREATE DATA r_line TYPE HANDLE struc_type_desc.
        CREATE DATA r_tab TYPE HANDLE tab_type_desc.
        CREATE DATA r_object TYPE HANDLE obj_type_desc.
        CREATE DATA r_obj TYPE REF TO object.
        ASSIGN r_tab->* TO <tab>.
        LOOP AT object_table REFERENCE INTO r_object.
          APPEND INITIAL LINE TO <tab> REFERENCE INTO r_line.
          ASSIGN r_object->* TO <object>.
          ASSIGN r_obj->* TO <obj>.
          MOVE <object> TO <obj>.
          ASSIGN <obj>->(field_name) TO <key>.
          ASSIGN r_line->* TO <line>.
          ASSIGN COMPONENT 'KEY' OF STRUCTURE <line> TO <fs_key>.
          ASSIGN COMPONENT 'OBJECT' OF STRUCTURE <line> TO <fs_object>.
          <fs_object> = <object>.
          <fs_key> = <key>.
        ENDLOOP.
        DATA: sort_field TYPE fieldname.
        sort_field = 'KEY'.
        SORT <tab> BY (sort_field).
        REFRESH object_table.
        LOOP AT <tab> REFERENCE INTO r_line.
          APPEND INITIAL LINE TO object_table REFERENCE INTO r_object.
          ASSIGN r_line->* TO <line>.
          ASSIGN r_object->* TO <object>.
          ASSIGN COMPONENT 'OBJECT' OF STRUCTURE <line> TO <fs_object>.
          <object> = <fs_object>.
        ENDLOOP.
      ENDMETHOD.

  • Standard versus sorted tables

    Hi,
    in SE30 (abap runtime analysis) i have tried to possible solutions for a DB access, and according to the performance tuning rules you should use sorted(or hashed) tables in stead of standard table, but in my case the runtime is almost equal. How is that possible ? Any explanations ?
    Situation : table RSSELDONE, more than 80000 records
    Code 1 with standard table - runtime 6.710.000 ms
    data: i_tab type table of rsseldone,
          lwa like line of i_tab.
    select * from rsseldone into table i_tab.
    read table i_tab into lwa
      with key rnr = 'REQU_3N57ZUZODOJ53FHTMO97BKDTH'.
    Code 2 with sorted table - runtime 7.051.939 ms
    data: i_stab type sorted table of rsseldone
              with non-unique key
                   rnr
              initial size 0,
          lwa like line of i_stab.
    select * from rsseldone into table i_stab.
    read table i_stab into lwa
      with table key rnr = 'REQU_3N57ZUZODOJ53FHTMO97BKDTH'.
    Strange !

    hi,
    <u>Standard Table</u> - the most commonly used type of table. You can sort and resort this table anytime. You can have duplicate records in them. Recommend that when accessing these tables, you sort them by a key and then READ via a BINARY SEARCH - better performance. When you write to this table the record is "appended" to the end of the table. In order to maintain the sort sequence (if any) you must use the SORT command again.
    <u>Sorted table</u> - this table has a defined sort sequence. You cannot resort. You can have duplicates. When you READ these tables, SAP automatically tries to use a BINARY SEARCH. Because you use a Binary Search, the retrieval time isexpodential to the number of records. When you write a record to this table the table is resorted.
    <u>Hashed Table</u> - this table has a defined key. When you write to the table it uses a hashing algorithm to identify where the record is stored (think if this as writing the location of a page in an index of a book). When you READ this table the system looks up this "index" and retrieves the record. Because of this the retrieval time is constant. Writing to this type of table takes the most time as it needs to calculate the hashing algorithm.
    Just go thorugh this link
    http://help.sap.com/saphelp_46c/helpdata/EN/fc/eb35de358411d1829f0000e829fbfe/frameset.htm
    Regard
    anver

  • Currency Format in Spry Sort Table

    Any ideas on how to format all numbers in a spry sort table
    into US currency? Currently on my site, Spry is not displaying the
    ".00" that is included in my XML file.
    My
    Spry Sort Table Example

    Hi,
    yes, I`ve had the same behavior. As a workaround, you have to change the format of the cells.
    Go into the properties of the cells:
    -> Right mouse click
    -> format cells
    -> category
    -> number
    -> change something, e.g. the number of decimal places to show
    Then you will have to map the component again to the same cells under "Display Data".
    And now, the currency information will be shown correctly.
    Regards
    Victor

  • Internal error - insert in sorted tabl ZADRU with

    Hello Experts,
    While i open BP transaction for one of the business partner. We are getting the following error:
    *Internal error - insert in sorted tabl ZADRU with*.
    Request your help to resolve this issue. Do we have some SAP note to handle such scenarios. It seems the data has become inconsistent.
    Thanks,
    Rohit

    Hi, Rohit
    Table ZADRU - it's your own development, please ask abap-team about this table.
    Denis

  • Can't we use Binary SEARCH  for TYPE SORTED TABLE?(Performance Improvement)

    Hi Expert!
                       I have declare a sorted type table with NON -UNIQUE, and want to use Binary search in read statement. But while  using bunary search in read statement I'm facing an error. The ERROR is
    "Table LI_MARC is a SORTED TABLE or INDEX TABLE. The BINARY SEARCH
    addition is only allowed for these tables if the key specified is an
    initial part of the table key."
    Please find detail
    TYES: tt_marc  TYPE SORTED TABLE OF marc   WITH NON-UNIQUE KEY matnr,werks.
    DATA: li_marc type tt_marc.
    READ TABLE li_marc INTO marc WITH KEY matnr = i_mbew-matnr     
                                                                          werks = i_mbew-bwkey BINARY SEARCH . 
    To my understanding , there is no need to mention Bianry Search  for sorted table TYPE. Please  let me know can  i use ?

    Hello,
    there is no need to mention Bianry Search for sorted table TYPE.
    Yes, this is because for SORTED TABLEs binary search algorithm is used by default for READ TABLE. Although you can use BINARY SEARCH addition but it's use is redundant.
    As for your case you've defined the KEY fields incorrectly There shouldn't be any "comma(s)" between the fields.
    TYPES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr werks.
    When you define it with commas
    TYPES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr, werks.
    the result is something like this:
    TYPES: tt_marc TYPE SORTED TABLE OF marc WITH NON-UNIQUE KEY matnr.
    TYPES: werks.
    Hence you were getting the syntax error!
    BR,
    Suhas
    PS: As for MARC you can use UNIQUE KEY addition because MATNR & WERKS are the key fields in the table.

  • Memory and performance  when copying a sorted table to a standard table

    Hello,
    As you all probably know, it's not possible to use a sorted table as a tables parameter of a function module, but sometimes you want to use a sorted table in your function module for performance reasons, and at the end of the function module, you just copy it to a standard table to return to the calling program.
    The problem with this is that at that moment, the contents of the table is in memory twice, which could result in the well known STORAGE_PARAMETERS_WRONG_SET runtime exception.                                                                               
    I've been looking for ways to do this without using an excessive amount of memory and still being performant.  I tried four methods, all have their advantages and disadvantages, so I was hoping someone here could help me come up with the best way to do this.  Both memory and performance are an issue. 
    Requirements :
    - Memory usage must be as low as possible
    - Performance must be as high as possible
    - Method must work on all SAP versions from 4.6c and up
    So far I have tried 3 methods.
    I included a test report to this message, the output of this on my dev system is :
    Test report for memory usage of copying tables    
    table1[] = table2[]                                        
    Memory :    192,751  Kb                                    
    Runtime:    436,842            
    Loop using workarea (with delete from original table)      
    Memory :    196,797  Kb                                    
    Runtime:  1,312,839        
    Loop using field symbol (with delete from original table)  
    Memory :    196,766  Kb                                    
    Runtime:  1,295,009                                                                               
    The code of the program :
    I had some problems pasting the code here, so it can be found at [http://pastebin.com/f5e2848b5|http://pastebin.com/f5e2848b5]
    Thanks in advance for the help.
    Edited by: Dries Horions on Jun 19, 2009 1:23 PM
    Edited by: Dries Horions on Jun 19, 2009 1:39 PM
    Edited by: Dries Horions on Jun 19, 2009 1:40 PM
    Edited by: Dries Horions on Jun 19, 2009 1:40 PM

    I've had another idea:
    Create a RFC function like this (replace SOLI_TAB with your table types):
    FUNCTION Z_COPY_TABLE .
    *"*"Lokale Schnittstelle:
    *"  IMPORTING
    *"     VALUE(IT_IN) TYPE  SOLI_TAB
    *"  EXPORTING
    *"     VALUE(ET_OUT) TYPE  SOLI_TAB
    et_out[] = it_in[].
    ENDFUNCTION.
    and then try something like this in your program:
    DATA: gd_copy_done TYPE c LENGTH 1.
    DATA: gt_one TYPE soli_tab.
    DATA: gt_two TYPE soli_tab.
    PERFORM move_tables.
    FORM move_tables.
      CLEAR gd_copy_done.
      CALL FUNCTION 'Z_COPY_TABLE'
        STARTING NEW TASK 'ztest'
        PERFORMING copy_done ON END OF TASK
        EXPORTING
          it_in = gt_one[].
      CLEAR gt_one[].
      WAIT UNTIL gd_copy_done IS NOT INITIAL.
    ENDFORM.
    FORM copy_done USING ld_task TYPE clike.
      RECEIVE RESULTS FROM FUNCTION 'Z_COPY_TABLE'
       IMPORTING
         et_out        = gt_two[].
      gd_copy_done = 'X'.
    ENDFORM.
    Maybe this is a little bit faster than the Memory-Export?
    Edited by: Carsten Grafflage on Jul 20, 2009 11:06 AM

  • Reading a sorted table in Sequence

    Hi,
       I have a sorted table and want to read it in a sequence.
    Say for example:
    Table: sort by secondary key field2, non unique
    Field1      Field2
    10             100
    20             100
    30             100
    Now, when i read the table with the secondray key, field2, I wnat that it should always return the data in same sequence i. e. 100, 200, 300
    But currently when the sequence is not maintained liek it can be 100, 200, 300 or 200, 100, 300
    Is it posisble that I get the same sequence every time.
    Thanks & Regards,
    Rupali Ray

    Hi,
    When you sort the table sort that table using the two fields that to in ascending order..
    this will make the internal table records in sequence like
    field1         field2
    10            100
    20            100
    30             100
    10             200
    20             200
    30              200
    Now whilw reading the table using the key 2 as 100 or 200 the value of field1 will be in sequence as desired.
    ie....             field1          field2
                        10              100
                         20             100
                        30               100
    Hope this will help.
    Regards,
    Rohan.
    Edited by: Rohan on Dec 4, 2008 1:02 PM

Maybe you are looking for