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

Similar Messages

  • 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.

  • 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.

  • Can we pass IT table name dynamically to READ and SORT stmt

    Hello All,
      i have a requirement in which i am passing table name using a variable and want to read the same table: so my question is can we execute read and sort stmt with dynamic IT name. please see below for explaination.
    v_itname = <it_2>.
    now read using variable
    READ table ( v_itname ) with key <field>.
    and
    SORT ( v_itname ) by (otab).
    thanks
    Mani

    Hi ,
    This can be done. Please refer to the  codes below. Please note that the code will work if the itabs are of type standard table else it may dump.
    You just need to replace the variables form the values from your internal table.
    DATA: v_table1(10) TYPE c VALUE 'I_MARA',
          v_field(10)  TYPE c VALUE 'MATNR',
          i_mara TYPE STANDARD TABLE OF mara.
    FIELD-SYMBOLS : <fs_tab>   TYPE STANDARD TABLE,
                    <fs_field> TYPE ANY.
    DATA: otab TYPE abap_sortorder_tab,
    oline TYPE abap_sortorder.
    SELECT * UP TO 10 ROWS
      FROM  mara
      INTO TABLE i_mara.
    IF sy-subrc = 0.
      ASSIGN (v_table1) TO <fs_tab>.
      IF sy-subrc = 0.
        oline-name = v_field.
        APPEND oline TO otab.
        SORT <fs_tab> BY (otab).
        READ TABLE <fs_tab>
        WITH KEY (v_field) = '000000000020000989' "
        BINARY SEARCH
        TRANSPORTING NO FIELDS.
        IF sy-subrc = 0.
        ENDIF.
      ENDIF.
    ENDIF.
    Regards,
    Dev.

  • 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

  • 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.

  • How do I read this "standard" table in my Function Module?

    I have a remote-enable Function Module (RFC).  I am receiving two tables as part of the parameters.  Table "A" is header information, and Table "B" is detail information.  So for every 1 "A" header record, I may have 1 to many "B" detail records.  I have a field we'll call "vendor_number" that is the common link between the two tables.
    Here's what I want to do:  I want to loop through table "A", and for each record, I want to do a READ on table "B", using the "ref_doc_no" from "A" as my key, to get the position of the first matching record.  I hold onto the value of the table index and then start looping table "B", adding 1 to the saved table index each time to process all of the detail records.
    Here's the problem:  This worked great as an ABAP program.  I had my "B" table declared with "ref_doc_no" as a non-unique key.  But when I ported my code over to the RFC, it told me that the RFC could only deal with standard tables.  I had to remove the "ref_doc_no" key declaration.  So now when I try to activate, I get an error similar to this:
    The declaration for the key field "another_field" is incomplete; however, "another_field" is contained in the key of table "B" and must be filled.
    I don't understand that.  I've not declared any keys for table "B".  I don't understand why it's thinking I need to populate "another_field" (I don't even know what the value would be).  My code to read the table (i.e. the line getting the error) is this:
    Priming read on table (sets the initial sy-tabix index value)
        READ TABLE it_incoming_invoice_line_item "table 'B'
          WITH TABLE KEY ref_doc_no =
                         wa_incoming_invoice_header-ref_doc_no
                    INTO wa_incoming_invoice_line_item.
    Is it possible for me to do some sort of direct read on a table in an RFC?  The only alternative I can think of would be to have to loop through table "B" until I find the first occurrence of a match.  Is that what I need to do?
    Thanks everyone.  Points, as always, awarded for helpful answers.

    Dave,
    1. You can fire SELECTS in an RFC as well, but in your case the data exists in SYSTEM A and the RFC is in System B, so you can't do that. You can fire SELECTS on tables in the same system.
    2. Quick example of two table loops - EKKO (HEADER) EKPO (ITEM).
    LOOP AT EKKO.
    LOOP AT EKPO WHERE EBELN = EKKO-EBELN.
    ENDLOOP.
    ENDLOOP.
    I hope this is clear now.
    Regards,
    Ravi

  • 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( ).

  • Read from cluster table ZL-PCL2

    Hi all,
    I need to read cluster table ZL that stores wage type for pernr. Now previously i was suggested
    FM 'CU_READ_RGDIR'
    FM 'CD_RED_LAST'.
    FM 'PYXX_READ_PAYROLL_RESULT'. But i want to use the statement
    Import from database.
    i have included the file RPC2ZL00.
    then the statement
    Import ZL to ZZL from database PCL2(ZL) ID ZL-KEY.
    Now does anyone have idea abt ZL-KEY??
    means what value i need to feed in ZL-KEy and how do i feed it??
    thanks in advance for all those who help me..
    Reena

    Hi Reena,
    Key is the combination of Pernr & sequence no., which u see it from report display payroll result(HINCLSTR) or RGDIR table.
    Instead of Import statement You can also use macro as below .
      CALL FUNCTION 'CU_READ_RGDIR'
           EXPORTING
                PERSNR          = PERNR-PERNR
           TABLES
                IN_RGDIR        = RGDIR
           EXCEPTIONS
                NO_RECORD_FOUND = 1
                OTHERS          = 2.
      CHECK SY-SUBRC = 0.
      PAY_BEGDA = SEL-BEGDA.
      LOOP AT RGDIR WHERE SRTZA = 'A'  AND VOID = SPACE
                      AND  ( PAYDT >= SEL-BEGDA AND PAYDT <= SEL-ENDDA ).
        IF RGDIR-RUNDT >= PAY_RUNDT.
          MOVE RGDIR-RUNDT TO PAY_RUNDT.
          PAY_BEGDA = RGDIR-FPBEG.
          SEQNR = RGDIR-SEQNR.
        ENDIF.
      ENDLOOP.
      RX-KEY-PERNR = PERNR-PERNR.
      UNPACK SEQNR TO RX-KEY-SEQNO.
      <b>RP-IMP-C2-RU.</b> 
      CHECK RP-IMP-RU-SUBRC = 0.
    Read the cluster table
      LOOP AT CRT.
      ENDLOOP.
      Hope this helps.
    Thanks,
    Sarika.

  • 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.

  • How to read an internal table with more than  one (2 or 3) key field(s).

    how to read an internal table with more than  one (2 or 3) key field(s). in ecc 6.0 version

    hi ,
    check this..
    report.
    tables: marc,mard.
    data: begin of itab occurs 0,
          matnr like marc-matnr,
          werks like marc-werks,
          pstat like marc-pstat,
          end of itab.
    data: begin of itab1 occurs 0,
          matnr like mard-matnr,
          werks like mard-werks,
          lgort like mard-lgort,
          end of itab1.
    parameters:p_matnr like marc-matnr.
    select matnr
           werks
           pstat
           from marc
           into table itab
           where matnr = p_matnr.
    sort itab by matnr werks.
    select matnr
           werks
           lgort
           from mard
           into table itab1
           for all entries in itab
           where matnr = itab-matnr
           and werks = itab-werks.
    sort itab1 by matnr werks.
    loop at itab.
    read table itab1 with key matnr = itab-matnr
                              werks = itab-werks.
    endloop.
    regards,
    venkat.

  • 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.

  • Sort table by field position?

    Hello,
    Is it possible to sort a table by field position?  For example, I have table ITAB with a 4 character field F1.  I want to sort the table first by the 3rd position ( itab-f12(1) ) ascending then the 4th position ( itab-f13(1) ) descending.
    data: begin of itab occurs 0,
              f1(4),
            end of itab.
    itab-f1 = '01AC'.
    append itab.
    itab-f1 = '02AB'.
    append itab.
    itab-f1 = '01CD'.
    append itab.
    itab-f1 = '02CA'.
    append itab.
    sort itab... 
    I thought about using TRANSLATE with a rule and converting each position to a numeric value (then transfer the value to a new 'sort' field), but I wasn't sure if there was an easier way.
    The sorted table should read:  '01AC' ; '02AB' ; '01CD' ; '02CA'
    Any help is appreciated.

    Hi,
    Please try this.
    DATA: BEGIN OF ITAB OCCURS 0,
            F1(4),
          END OF ITAB.
    DATA: BEGIN OF ITAB2 OCCURS 0,
            F1(1),
            F2(1),
            F3(4),
          END OF ITAB2.
    ITAB-F1 = '01AC'.
    APPEND ITAB.
    ITAB-F1 = '02AB'.
    APPEND ITAB.
    ITAB-F1 = '01CD'.
    APPEND ITAB.
    ITAB-F1 = '02CA'.
    APPEND ITAB.
    LOOP AT ITAB.
      ITAB2-F1 = ITAB-F1+2(1).
      ITAB2-F2 = ITAB-F1+3(1).
      ITAB2-F3 = ITAB-F1.
      APPEND ITAB2.
    ENDLOOP.
    SORT ITAB2 BY F1 ASCENDING
                  F2 DESCENDING.
    LOOP AT ITAB2.
      WRITE: / ITAB2-F3.
    ENDLOOP.
    Regards,
    Ferry Lianto

  • How to set default value of a table using sequence number

    Dear all,
    Does any body know that how to set default value of a table
    using sequence number.
    But I don't want to use trigger to do that.
    Please help!!!!
    Eldon

    Andrew is essentially correct. You can get around the trigger,
    but not the sequence, if (and this may be a very big if) you can
    guarantee that every time an insert is done into the table, from
    whatever source, the statement looks something like
    INSERT INTO tbl VALUES (sequence.nextval,other_columns_values)

  • How to insert record in sorted table

    Hi,
    Please tell me how to inser the record in the sorted internal table. This is the code which is not working properly. just tell me what r the changes need to b done.
    Thanks,(reward points for sure)
    DATA: BEGIN OF connection,
            cityfrom TYPE spfli-cityfrom,
            cityto   TYPE spfli-cityto,
            distid   TYPE spfli-distid,
            distance TYPE spfli-distance,
          END OF connection.
    DATA connection_tab LIKE sorted TABLE OF connection
                        WITH  KEY cityfrom
                                     with header line.
    SELECT cityfrom cityto distid distance
           FROM spfli
           INTO connection.
      INSERT connection INTO connection_tab.
    ENDSELECT.
    loop at connection_tab.
    write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
    endloop.
    connection-cityfrom = 'Bangalore'.
    connection-cityto = 'Delhi'.
    connection-cityfrom = 'KL'.
    connection-cityfrom = '2500'.
    insert connection to  connection_tab .
    loop at connection_tab.
    write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
    endloop.

    Hi,
    sorry that's by mistake.. but  i m getting runtime error if i insert record into sorted table
    DATA: BEGIN OF connection,
    cityfrom TYPE spfli-cityfrom,
    cityto TYPE spfli-cityto,
    distid TYPE spfli-distid,
    distance TYPE spfli-distance,
    END OF connection.
    DATA connection_tab LIKE sorted TABLE OF connection
    WITH  unique KEY cityfrom
    with header line.
    SELECT cityfrom cityto distid distance
    FROM spfli
    INTO connection.
    INSERT connection INTO connection_tab.
    ENDSELECT.
    loop at connection_tab.
    write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
    endloop.
    connection-cityfrom = 'Bangalore'.
    connection-cityto = 'Delhi'.
    connection-distid = 'KL'.
    connection-distance = '2500'.
    insert connection into table connection_tab .
    loop at connection_tab.
    write: / connection_tab-cityfrom, connection_tab-cityto, connection_tab-distid, connection_tab-distance.
    endloop.

Maybe you are looking for

  • Problem with XML on Linux

    hi everybody, I've a big problem with XML on Linux, in details I see my program stopping on Linux at the instruction XMLReader xr = XMLReaderFactory.createXMLReader("org.apache.crimson.parser.XMLReaderImpl"); and it's strange because on Windows it ru

  • I am having a problem with my iphone 4s "To finish setting up iCloud, iMessage, and FaceTime enter the apple ID password..."

    I was using my iphone just like any normal day and out of blue it went off because I let the battery die it was 1% and I didn't put on charger, I forgot so I put it on charger just like any normal day and it charged for sometime then it started to tu

  • Was this database migrated from dev or prod?

    We have several environments (e.g., development, staging, test, training, production).  When migrating a production database to a new version of SQL, we also migrate the related environments. Sometimes the developers want a refresh from production in

  • How to access excel(macros defined) in Infoview?

    Hi All, Can anyone help me out to know how to view Excel with Macros in Infoview. Regards, Anisa

  • Settlement rule for order

    hi co guru sir....kindly guide me to maintain  settlement rule for production order. steps by steps..plz.. problem is this when i create planned order to production order ..first  screen open for maintain settlement rule...i have maintained..but may