Hashed & sorted internal tables

hi all,
    can any body help me to understand the concept of <b>hashed & sorted</b> internal table  & how they can be used for improve the performance of report.
regards
Deepak

Hi Deepak,
If you have an internal table in your program which is used solely for lookup, it is good programming practice to use a hash table. The example below shows this, in combination with a method for buffering SELECT SINGLE results.
Code
*&      Form  select_dispo
      Get MRP controller and in-house production time from material
      and plant
     --> MATNR  Material
     --> RESWK  Plant
     <-- DISPO  MRP controller
     <-- DZEIT  In-house production time
form select_from_marc using matnr werks dispo dzeit.
  types: begin of mrp_lookup_type,
           matnr like marc-matnr,
           werks like marc-werks,
           dispo like marc-dispo,
           dzeit like marc-dzeit,
         end of mrp_lookup_type.
Define static hashed table to hold results
  statics: st_mrp type hashed table of mrp_lookup_type
                  with unique key matnr werks.
  data: l_wa_mrp type mrp_lookup_type.
  clear dzeit.
See if data is in the table
  read table st_mrp into l_wa_mrp with table key matnr = matnr
                                                 werks = werks.
If not in table, get it from the database
  if not sy-subrc is initial.
    select single dispo dzeit from marc
        into corresponding fields of l_wa_mrp-dispo
        where matnr eq matnr
          and werks eq werks.
Insert into table
    l_wa_mrp-matnr = matnr.
    l_wa_mrp-werks = werks.
    insert l_wa_mrp into table st_mrp.
  endif.
  dispo = l_wa_mrp-dispo.                      " MRP Controller
  dzeit = l_wa_mrp-dzeit.                      " Inhouse production time
endform.                    " select_from_marc

Similar Messages

  • How to find min and max of a field from sorted internal table

    Hi,
    I have sorted Internal Table by field f1.
    How do I find max and min value of f1.
    For min value of f1 I am using,
    READ TABLE IT1 INDEX 1.
    IT1-F1 = MIN.
    Is this correct? And how do I find the max value of f1 from this table.
    Thanks,
    CD

    Yes, that is right, and you can get the max like this.
    data: lv_lines type i.
    * get min
    READ TABLE IT1 INDEX 1.
    MIN  = IT1-F1.
    * get max
    lv_lines = lines( it1 ).
    read table it1 index lv_lines.
    MAX  = IT1-F1.
    Regards,
    Rich Heilman

  • Sorting internal table by date

    Hello experts,
                            i wat to sort internal table in asscending order and am using the code as follows,
                APPEND wa_final TO it_final.
                sort it_final by edatu vbeln  ASCENDING.
    am getting output as 05.09.2008
                                   10.09.2008
                                    27.08.2008
    but i want in 27.08.2008
                      05.09.208
                      10.09.2008
    please help me ASAP.
    Thanks,
    vino....

    Hi
    I think you uploaded date field as your output format. If it is in ddmmyyyy format, when you sort it, automatically it will sort. Check your input entries.
    Otherwise, what you had written is correct.
    check your code
    Regards,
    Dhanunjaya Reddy.

  • How to sort internal table

    Hi
    How to sort internal by binary search...please don't suggest SORT TABLE or HASHED table to use...

    hi,
    Use SORT Statement....
    i.e,
    sort itab.
    Here is the code
    TYPES: BEGIN OF PERSON_TYPE,
    NAME(10) TYPE C,
    AGE TYPE I,
    COUNTRY(3) TYPE C,
    END OF PERSON_TYPE.
    DATA: PERSON TYPE STANDARD TABLE OF PERSON_TYPE WITH
    NON-UNIQUE DEFAULT KEY INITIAL SIZE 5,
    WA_PERSON TYPE PERSON_TYPE.
    WA_PERSON-NAME = 'Muller'. WA_PERSON-AGE = 22.
    WA_PERSON-COUNTRY = 'USA'.
    APPEND WA_PERSON TO PERSON.
    WA_PERSON-NAME = 'Moller'. WA_PERSON-AGE = 25.
    WA_PERSON-COUNTRY = 'FRG'.
    APPEND WA_PERSON TO PERSON.
    WA_PERSON-NAME = 'Möller'. WA_PERSON-AGE = 22.
    WA_PERSON-COUNTRY = 'USA'.
    APPEND WA_PERSON TO PERSON.
    WA_PERSON-NAME = 'Miller'. WA_PERSON-AGE = 23.
    WA_PERSON-COUNTRY = 'USA'.
    APPEND WA_PERSON TO PERSON.
    SORT PERSON.
    SORT PERSON BY NAME AS TEXT
    SORT PERSON DESCENDING BY COUNTRY AGE NAME.
    SORT PERSON DESCENDING BY AGE ASCENDING NAME AS TEXT.
    Reward if it helps,
    Regards,
    Santosh

  • SORT INTERNAL TABLE USING NON KEY OF THE INTERNAL TABLE

    HI,
    i have one query for the cdpos table of abap.
    What i am looking is i want the latest CHANENR of the cdpos for that
    objectid  and tabname and fname in my internal table.
    what i thought of doing was to sort my internal table with objectid changnr tabname fname in descending order
    and than use delete adjacent duplicates command
    BUt that is not sorting based on all field , its sorting on changnr only
    please let me know what can i do

    no, that is not what i am looking at,
    I am saying say i have internal table cdpos
    OBJECTCLAS      OBJECTID    CHANGENR   TABNAME                        FNAME
    RECN_RECN      |0100TEST1   0000384409|    VICN01                        |RECNEND
    RECN_RECN       0100TEST1   0000383462    VICN01                          RECNLIFNR 
    RECN_RECN       0100TEST1    0000360190   VICN01                         RECNEND
    RECN_RECN        0100TEST1   0000340630    VICN01                         RECNEND
    this is my debug output after sorting on objectid changenr tabname fname in descending
    i wanted line 2nd to be at last so when i use delete adjacent command i can get 2 line item i.e 1st and 2nd line ...

  • Sorting internal table

    Hi all,
    I have a scenario wherein i have to sort the internal table without using the sort function( i.e sort syntax).Is there any logic.
    Can nebody pls help me out.
    Regards
    Jak

    Hai,
    To understand bubble sort, think of an air bubble rising in water
    To sort N items, N passes are made through the data.
    The result of the first pass is that the smallest item is in the last location of the array.
    The result of the second pass is that the second smallest item is in the second last location of the array.
    etc.
    After N passes, the entire array is sorted.
    The operation in each pass is as follows:
    First, the values in the first two locations are compared. If necessary the values are exchanged, so that the smaller one is last.
    Then, the values in the second and third locations are compared. If necessary the values are exchanged, so that again the smaller one is last.
    This process repeats to the end of the array.
    In effect, the smaller item bubbles its way towards the top. It keeps on going until either it reaches the top (and the pass ends), or it strikes a smaller item. In that case it stops itself, and gives that smaller item a nudge to start it on its way.
    If a complete pass is made without any exchanges being made, the data must already be sorted. This is easily checked. Thus it might be possible to halt the algorithm without going through all N passes.

  • How to sort internal tables of unknown structure?

    Hello
    Itab is an internal table of unknown structure with field F1 and many other.
    How to sort this table by field F1 is the structure is unknown?
    SORT ITAB by F1 ascending.
    Thanks

    Hello,
    Which version of SAP are you using?
    As of Release 701, you can specify the fields dynamically by specifying the fields in an internal table of type ABAP_SORTORDER_TAB. Further read can be found here: [SORT by (otab)|http://help.sap.com/abapdocu_702/en/abapsort_itab.htm#!ABAP_ADDITION_5@5@].
    For prior releases you can try something like this:
    SORT itab BY ('F1') ('F2) ... ('Fn')
    Hope this helps.
    BR,
    Suhas

  • Sort Internal table based on another internal table

    Hello All,
    My Requirement is :
    I have two internal tables itab1 and itab2. itab1 has partner_number along with some more fields/columns. Based on the partner_numbers of the itab1 i write a query to get the values for partner_last_name and central_block_flag from the table but000 and i fill these values into a new itab2.
    Sort itab2 by partner_last_name and central_block.
    Now how do I sort itab1 based on the sorted itab2-partner_number. I need to have itab1 sorted similar to the order in the itab2.
    How do i do this?
    Please let me know if you need more details.Looking forward for your support.
    Regards,
    Harish P M

    Hello Micky,
    Thank you for your early reply.
    I have this scenario wherein i need to sort a existing internal table itab1 of type 'bapibus1006_relations' based on the 'Partner last name ' and 'Inactive/Active Flag'. These two fields are not available in this itab1 and so i need to create itab2 after a query on table but000.
    Sorting itab2 is , first sort itab2 based on the 'Active flag' and then sort this itab2 again by 'Partner last name'(ascending order).
    Finally when i get my sorted itab2 i would have to ensure that my objective of sorting itab1 is obtained.
    I guess i sound better now.
    Would be helpful if you could reply.
    Regards,
    Harish P M

  • Sorting internal table with line types

    Hi,
    I have internal table juts for an example with four entries as below:
    A[]
    Line.....Line Types
    444001.....P
    New York...C 
    Evershine..B
    Mary.......N
    I want to sort the internal table with line types in order of lin types NBCP.
    How can i do this ?
    Please help.
    Note: Above example is just with four entries, there might be internal table with ten entries and ten defined sorting order for line types.

    Hi Tushar,
    Please note that we can't changes the mandatory sequence of the address format as defined in the country specif address format. We can change the sequence of others fields by line_priority.
    Try to change the address type :
    ADDRESS_TYPE - Address type (from 3.0C)
    There are three types of address:
    Address type '1': addresses of firms or organizations; the address structure which is used in most SAP applications as 'Address'.
    Address type '2': address of a person
    Address type '3': work address, usually the address of a contact person in a company
    Please use T/code "OY01"> Select Country> Example :AU"--> Display --> Select address key and press F1. You will find SAP 's Address format configuration .
    sap help:
    Formatting Routine Key for Printing Addresses
    For printing addresses, there are country-specific routines which in each case copy the correct postal formatting of the address.
    The three-character "Address Layout Key" for the recipient country controls which of the routines available for formatting addresses in the relevant country is used.
    These routines are programmed into the ADDRESS_INTO_PRINTFORM function module.
    They are based on different national and international guidelines and norms, including:
    ISO 11180,
    contracts of the World Postal Union (Seoul 1994),
    international address samples from the World Postal Union
    as well as the available rules of the individual countries.
    Below you will find an overview of the country-specific formats currently implemented.
    Customers can program their own formatting routines using a customer exit. The SZAD0001 SAP enhancement has been defined in the package SZAD for this (-> transaction CMOD).
    General formatting rules
    The following parameters are used depending on the transaction:
    whether the company address (street/house number) or the P.O. Box address is printed if both exist,
    how many lines are available for printing,
    which is the sender country.
    If there are not enough lines, then lines are left out according to a standard sequence.
    The address format depends on whether the sender country is the same as, or different from, the recipient country. The country is always specified from abroad, either as a text name, or as an identification code of up to three characters (license plate code or country key).
    Where the country name is written out in full, it is written in the language of the sender country. If a language is not specified for the sender country, or the sender country itself is not specified, the logon language is used instead.
    Exception: the language for the country code can be explicitly overwritten by a parameter in the print program (e.g. when the country code for customs transit papers is always to be specified in a particular language, such as English). if the "Print country name in recipient language" flag is set in the print program, the recipient language is used.
    Other language-dependent components such as the title and the word 'PO Box' are printed in the recipient language or the recipient country language. If this cannot be determined, the logon language is again used.
    For all formats except Great Britain (006), Japan (013), and South Korea (017), the core of the address is formatted as follows (without empty lines, except for the compulsory empty line:)
    title line (if applicable)
    name block (differs depending on the address type, see below)
    street address or PO Box
                            (compulsory empty line, if applicable)
    city line with postal code
    country code (if applicable)
    The city line and the country name are always printed in upper case for foreign addresses (only for the complete address, not for short forms).
    The name block generally consists of the following:
    "Normal" addresses (address type SPACE and address type 1):
    NAME1
    NAME2
    NAME3
    NAME4
    Personal addresses (address type 2):
    Title of person and name of person
    Business address with department and contact person (address type 3):
    NAME1
    NAME2
    NAME3
    NAME4
    department
    title of person and name of person
    In addresses entered using Business Address Services (central address management) (see Release notes Central Address Management for Release 4.0 and Central Address Management for Release 4.5 ), the street address can comprise several lines (see Print street address), otherwise street and house number are maintained in the Street field.
    Some countries do not have a compulsory empty line (see notes below). The city and district are printed in the city line, connected by a hyphen (exceptions: 004 USA, 006 Great Britain/Ireland, 013 Japan, 015 Germany, 017 South Korea, 019 Denmark), provided that the total length does not exceed 35 characters. If a different city is specified for the PO Box (PFORT), this is used in the PO Box address.
    In all formats which use a country code (currently 001 European standard format 002 Italy, 011 Switzerland and 014 Austria ), the license plate code for that country is used. If this is not maintained, the country key in table T005 is used.
    If the "Print country name in foreign addresses" flag is set for the sender country in table 005, the country code is not used; the country name is printed in the last line of the address.
    Formats 004 (USA), 005 (Canada) and 008 (Singapore) contain a line ('F') for the function of the contact person in the company (if address type = '3'). This line comes immediately after the line 'N' (Name (and title) of the natural person).
    In formats 002 (Italy), 004 (USA), 005 (Canada), 006 (Great Britain), 007 (Brazil) and Australia (009), the REGIO field (Region, State, Province, County) is formatted. For the USA, Canada, Brazil and Australia, the key from table T005S is used; for Great Britain the text name from table T005U.
    In all countries for which no "Address structure key" is maintained, a standard format is used which corresponds to format "010".
    Hope this may help you.
    Lanka

  • Sorting internal table with variable no of fields

    Hi ,
    I want to sort the internal table with variable no of fields . Every time the  report is run the number of fields as well as the sequence by which the table has to be sorted changes . How to do this .
    regards

    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.
    REWARD POINTS IF HELPFUL

  • Sorting internal table isue

    Hello,
    I am having problems sorting a table.
    The internal table has following data:
    Doc_num..........ver_num
    TEST123.............02
    TEST123.............01
    TESTXYZ.............02
    TESTXYZ.............03
    TESTXYZ.............01
    TESTXYZ.............04
    Now I am using statement :
    SORT itab by doc_num ver_num.
    Now this does sort the data according to correct doc_num but not according to ver_num.
    Please help.
    Thanks.
    Regards,
    Rajesh

    Note: I have defined doc_num and ver_num s string....
    My input is:
    TEST123.............1
    TEST123.............2
    TESTXYZ.............1
    TESTXYZ.............20
    TESTXYZ.............10
    TESTXYZ.............2
    I am seeing following:
    TEST123.............1
    TEST123.............1
    TESTXYZ.............1
    TESTXYZ.............10
    TESTXYZ.............20
    TESTXYZ.............2
    I want to see as follows:
    TEST123.............1
    TEST123.............2
    TESTXYZ.............1
    TESTXYZ.............2
    TESTXYZ.............10
    TESTXYZ.............20

  • Differences between Standard , sorted and hashed internal tables

    Can any body please tell me what are the main Differences between
    1) <b>Standard internal table</b>
    2) <b>Hashed internal table</b>
    3) <b>Sorted internal table</b>
    Please give me a clear idea about these Three.
    Thanks
    Prabhudutta<b></b>

    Hi,
    <b>Standard Internal Tables</b>
    Standard tables have a linear index. You can access them using either the index or the key. If you use the key, the response time is in linear relationship to the number of table entries. The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.
    This table type is particularly appropriate if you want to address individual table entries using the index. This is the quickest way to access table entries. To fill a standard table, append lines using the (APPEND) statement. You should read, modify and delete lines by referring to the index (INDEX option with the relevant ABAP command).  The response time for accessing a standard table is in linear relation to the number of table entries. If you need to use key access, standard tables are appropriate if you can fill and process the table in separate steps. For example, you can fill a standard table by appending records and then sort it. If you then use key access with the binary search option (BINARY), the response time is in logarithmic relation to
    the number of table entries.
    <b>Sorted Internal Tables</b>
    Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition.  Standard tables and sorted tables both belong to the generic group index tables.
    This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of
    table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.
    <b>Hashed Internal Tables</b>
    Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.
    This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and
    using internal tables that are similar to database tables.
    Regards
    Sudheer

  • Sorting a internal table

    hai all
    what is the effect of sorting the sorted internal table.
    thanks in advance

    Hello Sathish,
    If u declare an itab as sorted u cannot use the syntax for that itab.
    If useful reward.
    Vasanth

  • Internal Table statement

    INSERT, SORT, APPEND, MODIFY, COLLECT, READ, DELETE
    Which of the above statements are allowed to work with:
    Standard Internal Table?
    Sorted Internal Table?
    Hashed Internal Table?
    Thank You.

    Hi,
    <b>Append</b> is used to Fill <b>Standard Internal Tables</b>.
    <b>Insert</b> is used to Fill <b>Sorted Internal Tables & Hashed Internal Tables</b>.
    <b>Read</b>,<b>Delete</b>,<b>Modify</b>,<b>Collect</b>  will work in those <b>Three Internal Tables</b>.
    <b>Sort</b> is used to Sort <b>Standard & Hashed Interanl Table</b>.
    Regards,
    Padmam.

  • Types of internal tables with regard to EFFICIENCY

    Will any one tell me syntax to define each type of internal table  (standard, sorted , hashed , database) . how to compare their efficincy ( access time which is more effficent) is there any documantation or programme of such type exist then please tell  . i want to declare each type of above table and also to compare them w.r.t to efficeny thanks  want urgent reply

    Hi,
    There are 3 types of Internal tables.
    Standard Internal Tables:
    Standard tables have a linear index. You can access them using either the index or the key. If you use the key, the response time is in linear relationship to the number of table entries. The key of a standard table is always non-unique, and you may not include any specification for the uniqueness in the table definition.
    This table type is particularly appropriate if you want to address individual table entries using the index. This is the quickest way to access table entries. To fill a standard table, append lines using the (APPEND) statement. You should read, modify and delete lines by referring to the index (INDEX option with the relevant ABAP command). The response time for accessing a standard table is in linear relation to the number of table entries. If you need to use key access, standard tables are appropriate if you can fill and process the table in separate steps. For example, you can fill a standard table by appending records and then sort it. If you then use key access with the binary search option (BINARY), the response time is in logarithmic relation to the number of table entries.
    Sorted Internal Tables:
    Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition. Standard tables and sorted tables both belong to the generic group index tables.
    This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key.
    Hashed Internal Tables:
    Hashes tables have no internal linear index. You can only access hashed tables by specifying the key. The response time is constant, regardless of the number of table entries, since the search uses a hash algorithm. The key of a hashed table must be unique, and you must specify UNIQUE in the table definition.
    This table type is particularly suitable if you want mainly to use key access for table entries. You cannot access hashed tables using the index. When you use key access, the response time remains constant, regardless of the number of table entries. As with database tables, the key of a hashed table is always unique. Hashed tables are therefore a useful way of constructing and
    using internal tables that are similar to database tables.
    http://help.sap.com/saphelp_470/helpdata/EN/fc/eb35de358411d1829f0000e829fbfe/frameset.htm
    Regards,
    Kiran Sure

Maybe you are looking for