SORTED & HASHED tables

Hi all
     what exactly are the SORTED & HASHED tables??
Regards
Srini

Internal tables are the core of ABAP. They are like soul of a body. For any program we use
internal tables extensively. We can use Internal tables like normal data base tables only, but the
basic difference is the memory allocated for internal tables is temporary. Once the program is
closed the memory allocated for internal tables will also be out of memory.
But while using the internal tables, there are many performance issues to be considered. i.e which
type of internal table to be used for the program..like standard internal table, hashed internal
table or sorted internal table etc..
Internal tables
Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by
line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data
objects, they save the programmer the task of dynamic memory management in his or her programs. You should use internal tables
whenever you want to process a dataset with a fixed structure within a program. A particularly important use for internal tables is for
storing and formatting data from a database table within a program. They are also a good way of including very complicated data
structures in an ABAP program.
Like all elements in the ABAP type concept, internal tables can exist both as data types and as data objects A data type is the abstract
description of an internal table, either in a program or centrally in the ABAP Dictionary, that you use to create a concrete data object. The
data type is also an attribute of an existing data object.
Internal Tables as Data Types
Internal tables and structures are the two structured data types in ABAP. The data type of an internal table is fully specified by its line type,
key, and table type.
Line type
The line type of an internal table can be any data type. The data type of an internal table is normally a structure. Each component of the
structure is a column in the internal table. However, the line type may also be elementary or another internal table.
Key
The key identifies table rows. There are two kinds of key for internal tables - the standard key and a user-defined key. You can specify
whether the key should be UNIQUE or NON-UNIQUE. Internal tables with a unique key cannot contain duplicate entries. The uniqueness
depends on the table access method.
If a table has a structured line type, its default key consists of all of its non-numerical columns that are not references or themselves
internal tables. If a table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type
is an internal table, the default key is empty.
The user-defined key can contain any columns of the internal table that are not references or themselves internal tables. Internal tables
with a user-defined key are called key tables. When you define the key, the sequence of the key fields is significant. You should remember
this, for example, if you intend to sort the table according to the key.
Table type
The table type determines how ABAP will access individual table entries. Internal tables can be divided into three types:
Standard tables have an internal linear index. From a particular size upwards, the indexes of internal tables are administered as trees. In
this case, the index administration overhead increases in logarithmic and not linear relation to the number of lines. The system can access
records either by using the table index or the key. The response time for key access is proportional to the number of entries in the table.
The key of a standard table is always non-unique. You cannot specify a unique key. This means that standard tables can always be filled
very quickly, since the system does not have to check whether there are already existing entries.
Sorted tables are always saved sorted by the key. They also have an internal index. The system can access records either by using the
table index or the key. The response time for key access is logarithmically proportional 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. When you define the table, you must specify whether
the key is to be unique or not. Standard tables and sorted tables are known generically as index tables.
Hashed tables have no linear index. You can only access a hashed table using its key. The response time is independent of the number of
table entries, and is constant, since the system access the table entries using a hash algorithm. The key of a hashed table must be unique.
When you define the table, you must specify the key as UNIQUE.
Generic Internal Tables
Unlike other local data types in programs, you do not have to specify the data type of an internal table fully. Instead, you can specify a
generic construction, that is, the key or key and line type of an internal table data type may remain unspecified. You can use generic
internal tables to specify the types of field symbols and the interface parameters of procedures . You cannot use them to declare data
objects.
Internal Tables as Dynamic Data Objects
Data objects that are defined either with the data type of an internal table, or directly as an internal table, are always fully defined in
respect of their line type, key and access method. However, the number of lines is not fixed. Thus internal tables are dynamic data objects,
since they can contain any number of lines of a particular type. The only restriction on the number of lines an internal table may contain are
the limits of your system installation. The maximum memory that can be occupied by an internal table (including its internal administration)
is 2 gigabytes. A more realistic figure is up to 500 megabytes. An additional restriction for hashed tables is that they may not contain more
than 2 million entries. The line types of internal tables can be any ABAP data types - elementary, structured, or internal tables. The
individual lines of an internal table are called table lines or table entries. Each component of a structured line is called a column in the
internal table.
Choosing a Table Type
The table type (and particularly the access method) that you will use depends on how the typical internal table operations will be most
frequently executed.
Standard tables
This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest
possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by
specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship
with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in
separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key
access, the response time is logarithmically proportional to the number of table entries.
Sorted tables
This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries
are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add
them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always
uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the
table key in the WHERE condition.
Hashed tables
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index.
The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always
have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for
processing large amounts of data.
Creating Internal Tables
Like other elements in the ABAP type concept, you can declare internal tables as abstract data
types in programs or in the ABAP Dictionary, and then use them to define data objects.
Alternatively, you can define them directly as data objects. When you create an internal table as a
data object, you should ensure that only the administration entry which belongs to an internal
table is declared statically. The minimum size of an internal table is 256 bytes. This is important if an
internal table occurs as a component of an aggregated data object, since even empty internal
tables within tables can lead to high memory usage. (In the next functional release, the size of the
table header for an initial table will be reduced to 8 bytes). Unlike all other ABAP data objects, you
do not have to specify the memory required for an internal table. Table rows are added to and
deleted from the table dynamically at runtime by the various statements for adding and deleting
records.
You can create internal tables in different types.
You can create standard internal table and then make it sort in side the program.
The same way you can change to hashed internal tables also.
There will be some performance issues with regard to standard internal tables/ hashed internal
tables/ sorted internal tables.
Internal table types
This section describes how to define internal tables locally in a program. You can also define internal tables globally as data types in the
ABAP Dictionary.
Like all local data types in programs , you define internal tables using the TYPES statement. If you do not refer to an existing table type
using the TYPE or LIKE addition, you can use the TYPES statement to construct a new local internal table in your program.
TYPES <t> TYPE|LIKE <tabkind> OF <linetype> [WITH <key>]
[INITIAL SIZE <n>].
After TYPE or LIKE, there is no reference to an existing data type. Instead, the type constructor occurs:
<tabkind> OF <linetype> [WITH <key>]
The type constructor defines the table type <tabkind>, the line type <linetype>, and the key <key> of the internal table <t>.
You can, if you wish, allocate an initial amount of memory to the internal table using the INITIAL SIZE addition.
Table type
You can specify the table type <tabkind> as follows:
Generic table types
INDEX TABLE
For creating a generic table type with index access.
ANY TABLE
For creating a fully-generic table type.
Data types defined using generic types can currently only be used for field symbols and for interface parameters in procedures . The generic
type INDEX TABLE includes standard tables and sorted tables. These are the two table types for which index access is allowed. You cannot
pass hashed tables to field symbols or interface parameters defined in this way. The generic type ANY TABLE can represent any table. You
can pass tables of all three types to field symbols and interface parameters defined in this way. However, these field symbols and
parameters will then only allow operations that are possible for all tables, that is, index operations are not allowed.
Fully-Specified Table Types
STANDARD TABLE or TABLE
For creating standard tables.
<b>SORTED TABLE</b>
For creating sorted tables.
<b>HASHED TABLE</b>
For creating hashed tables.
Fully-specified table types determine how the system will access the entries in the table in key operations. It uses a linear search for
standard tables, a binary search for sorted tables, and a search using a hash algorithm for hashed tables.
Line type
For the line type <linetype>, you can specify:
Any data type if you are using the TYPE addition. This can be a predefined ABAP type, a local type in the program, or a data type from the
ABAP Dictionary. If you specify any of the generic elementary types C, N, P, or X, any attributes that you fail to specify (field length, number
of decimal places) are automatically filled with the default values. You cannot specify any other generic types.
Any data object recognized within the program at that point if you are using the LIKE addition. The line type adopts the fully-specified data
type of the data object to which you refer. Except for within classes, you can still use the LIKE addition to refer to database tables and
structures in the ABAP Dictionary (for compatibility reasons).
All of the lines in the internal table have the fully-specified technical attributes of the specified data type.
Key
You can specify the key <key> of an internal table as follows:
[UNIQUE|NON-UNIQUE] KEY <col1> ... <col n>
In tables with a structured line type, all of the components <coli> belong to the key as long as they are not internal tables or references,
and do not contain internal tables or references. Key fields can be nested structures. The substructures are expanded component by
component when you access the table using the key. The system follows the sequence of the key fields.
[UNIQUE|NON-UNIQUE] KEY TABLE LINE
If a table has an elementary line type (C, D, F, I, N, P, T, X), you can define the entire line as the key. If you try this for a table whose line
type is itself a table, a syntax error occurs. If a table has a structured line type, it is possible to specify the entire line as the key. However,
you should remember that this is often not suitable.
[UNIQUE|NON-UNIQUE] DEFAULT KEY
This declares the fields of the default key as the key fields. If the table has a structured line type, the default key contains all non-numeric
columns of the internal table that are not and do not contain references or internal tables. If the table has an elementary line type, the
default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty.
Specifying a key is optional. If you do not specify a key, the system defines a table type with an arbitrary key. You can only use this to
define the types of field symbols and the interface parameters of procedures . For exceptions, refer to Special Features of Standard Tables.
The optional additions UNIQUE or NON-UNIQUE determine whether the key is to be unique or non-unique, that is, whether the table can
accept duplicate entries. If you do not specify UNIQUE or NON-UNIQUE for the key, the table type is generic in this respect. As such, it can
only be used for specifying types. When you specify the table type simultaneously, you must note the following restrictions:
You cannot use the UNIQUE addition for standard tables. The system always generates the NON-UNIQUE addition automatically.
You must always specify the UNIQUE option when you create a hashed table.
Initial Memory Requirement
You can specify the initial amount of main memory assigned to an internal table object when you define the data type using the following
addition:
INITIAL SIZE <n>
This size does not belong to the data type of the internal table, and does not affect the type check. You can use the above addition to
reserve memory space for <n> table lines when you declare the table object.
When this initial area is full, the system makes twice as much extra space available up to a limit of 8KB. Further memory areas of 12KB each
are then allocated.
You can usually leave it to the system to work out the initial memory requirement. The first time you fill the table, little memory is used. The
space occupied, depending on the line width, is 16 <= <n> <= 100.
It only makes sense to specify a concrete value of <n> if you can specify a precise number of table entries when you create the table and
need to allocate exactly that amount of memory (exception: Appending table lines to ranked lists). This can be particularly important for
deep-structured internal tables where the inner table only has a few entries (less than 5, for example).
To avoid excessive requests for memory, large values of <n> are treated as follows: The largest possible value of <n> is 8KB divided by the
length of the line. If you specify a larger value of <n>, the system calculates a new value so that n times the line width is around 12KB.
Examples
TYPES: BEGIN OF LINE,
COLUMN1 TYPE I,
COLUMN2 TYPE I,
COLUMN3 TYPE I,
END OF LINE.
TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.
The program defines a table type ITAB. It is a sorted table, with line type of the structure LINE and a unique key of the component
COLUMN1.
TYPES VECTOR TYPE HASHED TABLE OF I WITH UNIQUE KEY TABLE LINE.
TYPES: BEGIN OF LINE,
COLUMN1 TYPE I,
COLUMN2 TYPE I,
COLUMN3 TYPE I,
END OF LINE.
TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.
TYPES: BEGIN OF DEEPLINE,
FIELD TYPE C,
TABLE1 TYPE VECTOR,
TABLE2 TYPE ITAB,
END OF DEEPLINE.
TYPES DEEPTABLE TYPE STANDARD TABLE OF DEEPLINE
WITH DEFAULT KEY.
The program defines a table type VECTOR with type hashed table, the elementary line type I and a unique key of the entire table line. The
second table type is the same as in the previous example. The structure DEEPLINE contains the internal table as a component. The table
type DEEPTABLE has the line type DEEPLINE. Therefore, the elements of this internal table are themselves internal tables. The key is the
default key - in this case the column FIELD. The key is non-unique, since the table is a standard table.
Internal table objects
Internal tables are dynamic variable data objects. Like all variables, you declare them using the DATA statement. You can also declare static
internal tables in procedures using the STATICS statement, and static internal tables in classes using the CLASS-DATA statement. This
description is restricted to the DATA statement. However, it applies equally to the STATICS and CLASS-DATA statements.
Reference to Declared Internal Table Types
Like all other data objects, you can declare internal table objects using the LIKE or TYPE addition of the DATA statement.
DATA <itab> TYPE <type>|LIKE <obj> [WITH HEADER LINE].
Here, the LIKE addition refers to an existing table object in the same program. The TYPE addition can refer to an internal type in the
program declared using the TYPES statement, or a table type in the ABAP Dictionary.
You must ensure that you only refer to tables that are fully typed. Referring to generic table types (ANY TABLE, INDEX TABLE) or not
specifying the key fully is not allowed (for exceptions, refer to Special Features of Standard Tables).
The optional addition WITH HEADER line declares an extra data object with the same name and line type as the internal table. This data
object is known as the header line of the internal table. You use it as a work area when working with the internal table (see Using the
Header Line as a Work Area). When you use internal tables with header lines, you must remember that the header line and the body of the
table have the same name. If you have an internal table with header line and you want to address the body of the table, you must indicate
this by placing brackets after the table name (<itab>[]). Otherwise, ABAP interprets the name as the name of the header line and not of the
body of the table. You can avoid this potential confusion by using internal tables without header lines. In particular, internal tables nested
in structures or other internal tables must not have a header line, since this can lead to ambiguous expressions.
TYPES VECTOR TYPE SORTED TABLE OF I WITH UNIQUE KEY TABLE LINE.
DATA: ITAB TYPE VECTOR,
JTAB LIKE ITAB WITH HEADER LINE.
MOVE ITAB TO JTAB. <- Syntax error!
MOVE ITAB TO JTAB[].
The table object ITAB is created with reference to the table type VECTOR. The table object JTAB has the same data type as ITAB. JTAB also
has a header line. In the first MOVE statement, JTAB addresses the header line. Since this has the data type I, and the table type of ITAB
cannot be converted into an elementary type, the MOVE statement causes a syntax error. The second MOVE statement is correct, since
both operands are table objects.
Declaring New Internal Tables
You can use the DATA statement to construct new internal tables as well as using the LIKE or TYPE addition to refer to existing types or
objects. The table type that you construct does not exist in its own right; instead, it is only an attribute of the table object. You can refer to
it using the LIKE addition, but not using TYPE. The syntax for constructing a table object in the DATA statement is similar to that for defining
a table type in the TYPES statement.
DATA <itab> TYPE|LIKE <tabkind> OF <linetype> WITH <key>
[INITIAL SIZE <n>]
[WITH HEADER LINE].
As when you define a table type , the type constructor
<tabkind> OF <linetype> WITH <key>
defines the table type <tabkind>, the line type <linekind>, and the key <key> of the internal table <itab>. Since the technical attributes of
data objects are always fully specified, the table must be fully specified in the DATA statement. You cannot create generic table types (ANY
TABLE, INDEX TABLE), only fully-typed tables (STANDARD TABLE, SORTED TABLE, HASHED TABLE). You must also specify the key and whether
it is to be unique (for exceptions, refer to Special Features of Standard Tables).
As in the TYPES statement, you can, if you wish, allocate an initial amount of memory to the internal table using the INITIAL SIZE addition.
You can create an internal table with a header line using the WITH HEADER LINE addition. The header line is created under the same
conditions as apply when you refer to an existing table type.
DATA ITAB TYPE HASHED TABLE OF SPFLI
WITH UNIQUE KEY CARRID CONNID.
The table object ITAB has the type hashed table, a line type corresponding to the flat structure SPFLI from the ABAP Dictionary, and a
unique key with the key fields CARRID and CONNID. The internal table ITAB can be regarded as an internal template for the database table
SPFLI. It is therefore particularly suitable for working with data from this database table as long as you only access it using the key.

Similar Messages

  • URGENT - Sorting Hash Tables

    I am using a hash table with 2 columns. The first one has strings and is the key. The second column has integers.
    I need to sort this table on the first column and print the contents of the table.
    Then i need to sort it on the second column and print the results.
    How do i sort the hastables.
    Please let me know as soon as possible.
    Thanks and Regards,
    Vijay

    You got it all wrong. Hashtables cannot be sorted because then it would not be a hashtable. The content of the Hashtable can be sorted.
    What you want to do is get the key Set (keySet() method) of the Hashtable, wrap it in a List (e.g. LinkedList), sort that (see java.util.Collections for sorting) and then print out the contents of the Hashtable in the order pointed out by the keys in the sorted List.
    Then you can do the same for the values() Collection of the Hashtable.
    Pointers:
    http://java.sun.com/j2se/1.4/docs/api/java/util/Hashtable.html
    http://java.sun.com/j2se/1.4/docs/api/java/util/Set.html
    http://java.sun.com/j2se/1.4/docs/api/java/util/List.html
    http://java.sun.com/j2se/1.4/docs/api/java/util/LinkedList.html
    http://java.sun.com/j2se/1.4/docs/api/java/util/Collections.html

  • Question about sorted, hashed tables, mindset when using OO concepts...

    Hello experts,
    I just want to make sure if my idea about sorted and hashed table is correct.Please give tips and suggestions.
    In one of my reports, I declared a structure and an itab.
    TYPES: BEGIN OF t_mkpf,
            mblnr           LIKE mkpf-mblnr,
            mjahr           LIKE mkpf-mjahr,
            budat           LIKE mkpf-budat,
            xblnr(10)       TYPE c,
            tcode2          LIKE mkpf-tcode2,
            cputm           LIKE mkpf-cputm,
            blart           LIKE mkpf-blart,
          END OF t_mkpf.
    it_mkpf       TYPE SORTED   TABLE OF t_mkpf WITH HEADER LINE
                                       WITH NON-UNIQUE KEY mblnr mjahr.
    Now, I declared it as a sorted table with a non-unique key MBLNR and MJAHR. Now suppose I have 1000 records in my itab. how will it search for a particular record?
    2. Is it faster than sorting a standard table then reading it using binary search?
    3. How do I use a hashed table effectively? lets say that I want to use hashed type instead of sorted table in my example above.
    4. I am currently practicing ABAP Objects and my problem is that I think my mindset when programming a report is still the 'procedural one'. How do one use ABAP concepts effectively?
    Again, thank you guys and have a nice day!

    Hi Viray,
    <b>The different ways to fill an Internal Table:</b>
    <b>append&sort</b>
    This is the simplest one. I do appends on a standard table and then a sort.
    data: lt_tab type standard table of ...
    do n times.
    ls_line = ...
    append ls_line to lt_tab.
    enddo.
    sort lt_tab.
    The thing here is the fast appends and the slow sort - so this is interesting how this will compare to the following one.
    <b>read binary search & insert index sy-tabix</b>
    In this type I also use a standard table, but I read to find the correct insert index to get a sorted table also.
    data: lt_tab type standard table of ...
    do n times.
    ls_line = ...
    read table lt_tab transporting no fields with key ... binary search.
    if sy-subrc <> 0.
      insert ls_line into lt_tab index sy-tabix.
    endif.
    enddo.
    <b>sorted table with non-unique key</b>
    Here I used a sorted table with a non-unique key and did inserts...
    data: lt_tab type sorted table of ... with non-unique key ...
    do n times.
    ls_line = ...
    insert ls_line into table lt_tab.
    enddo.
    <b>sorted table with unique key</b>
    The coding is the same instead the sorted table is with a unique key.
    data: lt_tab type sorted table of ... with unique key ...
    do n times.
    ls_line = ...
    insert ls_line into table lt_tab.
    enddo.
    <b>hashed table</b>
    The last one is the hashed table (always with unique key).
    data: lt_tab type hashed table of ... with unique key ...
    do n times.
    ls_line = ...
    insert ls_line into table lt_tab.
    enddo.
    <b>You Can use this Program to Test:</b>
    types:
      begin of local_long,
        key1 type char10,
        key2 type char10,
        data1 type char10,
        data2 type char10,
        data3 type i,
        data4 type sydatum,
        data5 type numc10,
        data6 type char32,
        data7 type i,
        data8 type sydatum,
        data9 type numc10,
        dataa type char32,
        datab type i,
        datac type sydatum,
        datad type numc10,
        datae type char32,
        dataf type i,
        datag type sydatum,
        datah type numc10,
        datai type char32,
        dataj type i,
        datak type sydatum,
        datal type numc10,
        datam type char32,
        datan type i,
        datao type sydatum,
        datap type numc10,
        dataq type char32,
        datar type i,
        datas type sydatum,
        datat type numc10,
        datau type char32,
        datav type i,
        dataw type sydatum,
        datax type numc10,
        datay type char32,
        dataz type i,
        data11 type numc10,
        data21 type char32,
        data31 type i,
        data41 type sydatum,
        data51 type numc10,
        data61 type char32,
        data71 type i,
        data81 type sydatum,
        data91 type numc10,
        dataa1 type char32,
        datab1 type i,
        datac1 type sydatum,
        datad1 type numc10,
        datae1 type char32,
        dataf1 type i,
        datag1 type sydatum,
        datah1 type numc10,
        datai1 type char32,
        dataj1 type i,
        datak1 type sydatum,
        datal1 type numc10,
        datam1 type char32,
        datan1 type i,
        datao1 type sydatum,
        datap1 type numc10,
        dataq1 type char32,
        datar1 type i,
        datas1 type sydatum,
        datat1 type numc10,
        datau1 type char32,
        datav1 type i,
        dataw1 type sydatum,
        datax1 type numc10,
        datay1 type char32,
        dataz1 type i,
      end of local_long.
    data:
      ls_long type local_long,
      lt_binary type standard table of local_long,
      lt_sort_u type sorted table of local_long with unique key key1 key2,
      lt_sort_n type sorted table of local_long with non-unique key key1 key2,
      lt_hash_u type hashed table of local_long with unique key key1 key2,
      lt_apsort type standard table of local_long.
    field-symbols:
      <ls_long> type local_long.
    parameters:
      min1 type i default 1,
      max1 type i default 1000,
      min2 type i default 1,
      max2 type i default 1000,
      i1 type i default 100,
      i2 type i default 200,
      i3 type i default 300,
      i4 type i default 400,
      i5 type i default 500,
      i6 type i default 600,
      i7 type i default 700,
      i8 type i default 800,
      i9 type i default 900,
      fax type i default 1000.
    types:
      begin of measure,
        what(10) type c,
        size(6) type c,
        time type i,
        lines type i,
        reads type i,
        readb type i,
        fax_s type i,
        fax_b type i,
        fax(6) type c,
        iter type i,
      end of measure.
    data:
      lt_time type standard table of measure,
      lt_meantimes type standard table of measure,
      ls_time type measure,
      lv_method(7) type c,
      lv_i1 type char10,
      lv_i2 type char10,
      lv_f type f,
      lv_start type i,
      lv_end type i,
      lv_normal type i,
      lv_size type i,
      lv_order type i,
      lo_rnd1 type ref to cl_abap_random_int,
      lo_rnd2 type ref to cl_abap_random_int.
    get run time field lv_start.
    lo_rnd1 = cl_abap_random_int=>create( seed = lv_start min = min1 max = max1 ).
    add 1 to lv_start.
    lo_rnd2 = cl_abap_random_int=>create( seed = lv_start min = min2 max = max2 ).
    ls_time-fax = fax.
    do 5 times.
      do 9 times.
        case sy-index.
          when 1. lv_size = i1.
          when 2. lv_size = i2.
          when 3. lv_size = i3.
          when 4. lv_size = i4.
          when 5. lv_size = i5.
          when 6. lv_size = i6.
          when 7. lv_size = i7.
          when 8. lv_size = i8.
          when 9. lv_size = i9.
        endcase.
        if lv_size > 0.
          ls_time-iter = 1.
          clear lt_apsort.
          ls_time-what = 'APSORT'.
          ls_time-size = lv_size.
          get run time field lv_start.
          do lv_size times.
            perform fill.
            append ls_long to lt_apsort.
          enddo.
          sort lt_apsort by key1 key2.
          get run time field lv_end.
          ls_time-time = lv_end - lv_start.
          ls_time-reads = 0.
          ls_time-readb = 0.
          ls_time-lines = lines( lt_apsort ).
          get run time field lv_start.
          do.
            add 1 to ls_time-readb.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_apsort
              assigning <ls_long>
              with key key1 = lv_i1
                       key2 = lv_i2
              binary search.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do.
            add 1 to ls_time-reads.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_apsort
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_apsort
              assigning <ls_long>
              with key key1 = lv_i1
                       key2 = lv_i2
              binary search.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_b = lv_end - lv_start.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_apsort
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_s = lv_end - lv_start.
          collect ls_time into lt_time.
          clear lt_binary.
          ls_time-what = 'BINARY'.
          ls_time-size = lv_size.
          get run time field lv_start.
          do lv_size times.
            perform fill.
            read table lt_binary
              transporting no fields
              with key key1 = ls_long-key1
                       key2 = ls_long-key2
              binary search.
            if sy-index <> 0.
              insert ls_long into lt_binary index sy-tabix.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-time = lv_end - lv_start.
          ls_time-reads = 0.
          ls_time-readb = 0.
          ls_time-lines = lines( lt_binary ).
          get run time field lv_start.
          do.
            add 1 to ls_time-readb.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_binary
              assigning <ls_long>
              with key key1 = lv_i1
                       key2 = lv_i2
              binary search.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do.
            add 1 to ls_time-reads.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_binary
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_binary
              assigning <ls_long>
              with key key1 = lv_i1
                       key2 = lv_i2
              binary search.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_b = lv_end - lv_start.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_binary
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_s = lv_end - lv_start.
          collect ls_time into lt_time.
          clear lt_sort_n.
          ls_time-what = 'SORT_N'.
          ls_time-size = lv_size.
          get run time field lv_start.
          do lv_size times.
            perform fill.
            insert ls_long into table lt_sort_n.
          enddo.
          get run time field lv_end.
          ls_time-time = lv_end - lv_start.
          ls_time-reads = 0.
          ls_time-readb = 0.
          ls_time-lines = lines( lt_sort_n ).
          get run time field lv_start.
          do.
            add 1 to ls_time-readb.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_sort_n
              assigning <ls_long>
              with table key key1 = lv_i1
                             key2 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do.
            add 1 to ls_time-reads.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_sort_n
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_sort_n
              assigning <ls_long>
              with table key key1 = lv_i1
                             key2 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_b = lv_end - lv_start.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_sort_n
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_s = lv_end - lv_start.
          collect ls_time into lt_time.
          clear lt_sort_u.
          ls_time-what = 'SORT_U'.
          ls_time-size = lv_size.
          get run time field lv_start.
          do lv_size times.
            perform fill.
            insert ls_long into table lt_sort_u.
          enddo.
          get run time field lv_end.
          ls_time-time = lv_end - lv_start.
          ls_time-reads = 0.
          ls_time-readb = 0.
          ls_time-lines = lines( lt_sort_u ).
          get run time field lv_start.
          do.
            add 1 to ls_time-readb.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_sort_u
              assigning <ls_long>
              with table key key1 = lv_i1
                             key2 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do.
            add 1 to ls_time-reads.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_sort_u
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_sort_u
              assigning <ls_long>
              with table key key1 = lv_i1
                             key2 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_b = lv_end - lv_start.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_sort_u
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_s = lv_end - lv_start.
          collect ls_time into lt_time.
          clear lt_hash_u.
          ls_time-what = 'HASH_U'.
          ls_time-size = lv_size.
          get run time field lv_start.
          do lv_size times.
            perform fill.
            insert ls_long into table lt_hash_u.
          enddo.
          get run time field lv_end.
          ls_time-time = lv_end - lv_start.
          ls_time-reads = 0.
          ls_time-readb = 0.
          ls_time-lines = lines( lt_hash_u ).
          get run time field lv_start.
          do.
            add 1 to ls_time-readb.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_hash_u
              assigning <ls_long>
              with table key key1 = lv_i1
                             key2 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do.
            add 1 to ls_time-reads.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_hash_u
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data11 = sy-index.
            endif.
            get run time field lv_end.
            subtract lv_start from lv_end.
            if lv_end >= ls_time-time.
              exit.
            endif.
          enddo.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_hash_u
              assigning <ls_long>
              with table key key1 = lv_i1
                             key2 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_b = lv_end - lv_start.
          get run time field lv_start.
          do fax times.
            lv_i1 = lo_rnd1->get_next( ).
            lv_i2 = lo_rnd2->get_next( ).
            read table lt_hash_u
              assigning <ls_long>
              with key key2 = lv_i1
                       key1 = lv_i2.
            if sy-subrc = 0.
              <ls_long>-data21 = sy-index.
            endif.
          enddo.
          get run time field lv_end.
          ls_time-fax_s = lv_end - lv_start.
          collect ls_time into lt_time.
        endif.
      enddo.
    enddo.
    sort lt_time by what size.
    write: / ' type      | size   | time        | tab-size    | directread  | std read    | time direct | time std read'.
    write: / sy-uline.
    loop at lt_time into ls_time.
      write: / ls_time-what, '|', ls_time-size, '|', ls_time-time, '|', ls_time-lines, '|', ls_time-readb, '|', ls_time-reads, '|', ls_time-fax_b, '|', ls_time-fax_s.
    endloop.
    form fill.
      lv_i1 = lo_rnd1->get_next( ).
      lv_i2 = lo_rnd2->get_next( ).
      ls_long-key1 = lv_i1.
      ls_long-key2 = lv_i2.
      ls_long-data1 = lv_i1.
      ls_long-data2 = lv_i2.
      ls_long-data3 = lv_i1.
      ls_long-data4 = sy-datum + lv_i1.
      ls_long-data5 = lv_i1.
      ls_long-data6 = lv_i1.
      ls_long-data7 = lv_i1.
      ls_long-data8 = sy-datum + lv_i1.
      ls_long-data9 = lv_i1.
      ls_long-dataa = lv_i1.
      ls_long-datab = lv_i1.
      ls_long-datac = sy-datum + lv_i1.
      ls_long-datad = lv_i1.
      ls_long-datae = lv_i1.
      ls_long-dataf = lv_i1.
      ls_long-datag = sy-datum + lv_i1.
      ls_long-datah = lv_i1.
      ls_long-datai = lv_i1.
      ls_long-dataj = lv_i1.
      ls_long-datak = sy-datum + lv_i1.
      ls_long-datal = lv_i1.
      ls_long-datam = lv_i1.
      ls_long-datan = sy-datum + lv_i1.
      ls_long-datao = lv_i1.
      ls_long-datap = lv_i1.
      ls_long-dataq = lv_i1.
      ls_long-datar = sy-datum + lv_i1.
      ls_long-datas = lv_i1.
      ls_long-datat = lv_i1.
      ls_long-datau = lv_i1.
      ls_long-datav = sy-datum + lv_i1.
      ls_long-dataw = lv_i1.
      ls_long-datax = lv_i1.
      ls_long-datay = lv_i1.
      ls_long-dataz = sy-datum + lv_i1.
      ls_long-data11 = lv_i1.
      ls_long-data21 = lv_i1.
      ls_long-data31 = lv_i1.
      ls_long-data41 = sy-datum + lv_i1.
      ls_long-data51 = lv_i1.
      ls_long-data61 = lv_i1.
      ls_long-data71 = lv_i1.
      ls_long-data81 = sy-datum + lv_i1.
      ls_long-data91 = lv_i1.
      ls_long-dataa1 = lv_i1.
      ls_long-datab1 = lv_i1.
      ls_long-datac1 = sy-datum + lv_i1.
      ls_long-datad1 = lv_i1.
      ls_long-datae1 = lv_i1.
      ls_long-dataf1 = lv_i1.
      ls_long-datag1 = sy-datum + lv_i1.
      ls_long-datah1 = lv_i1.
      ls_long-datai1 = lv_i1.
      ls_long-dataj1 = lv_i1.
      ls_long-datak1 = sy-datum + lv_i1.
      ls_long-datal1 = lv_i1.
      ls_long-datam1 = lv_i1.
      ls_long-datan1 = sy-datum + lv_i1.
      ls_long-datao1 = lv_i1.
      ls_long-datap1 = lv_i1.
      ls_long-dataq1 = lv_i1.
      ls_long-datar1 = sy-datum + lv_i1.
      ls_long-datas1 = lv_i1.
      ls_long-datat1 = lv_i1.
      ls_long-datau1 = lv_i1.
      ls_long-datav1 = sy-datum + lv_i1.
      ls_long-dataw1 = lv_i1.
      ls_long-datax1 = lv_i1.
      ls_long-datay1 = lv_i1.
      ls_long-dataz1 = sy-datum + lv_i1.
    endform.".
    Thanks & Regards,
    YJR.

  • Difference Between Begin of itab occurs 0 and declaring Std,sort,Hash tab

    Can anyone explian the reason abt the begin of itab occurs 0
    Before 3.0 they use to define INternal tabls in this way.....
    Now, we are using Standard , Sorted, hashed tables...
    Can any body explain me abt the change that has occured and why it has occured?
    HAve a great day!
    Regards,
    Krishna Chaitanya
    Edited by: Alvaro Tejada Galindo on Apr 14, 2008 3:20 PM

    Hello,
    Thanks for your resposne!
    I got the answer in SAP HELP....
    Before 3.0 Internal Tables all had Header Lines and a Flat-structured line type. There were no independent Table types
    You could only create a Table Object using the occurs addition in data structures...
    But, now we can create a Table Type after 4.0 with which we can use itables more efficiently..as Data objects occupy memory and for Table type their will be no memory allocated.
    This is reason, I found.....
    Have a great day!
    Regards,
    Krishna Chaitanya

  • Sort Multiple Times on Hash Table

    I have a hash table that the key is id, value is a string of first name, last name, and age.
    for example:
    Hashtable showHT = new Hashtable();
    showHT.put(person.getId(), person); <--- person is an object that contains all information
    How to do sorting?
    If I want to sort by id, last name, first name, and age, how can I do it.
    I just know how to do once:
    for exmpale, sorting by id:
    Vector v = new Vector(showHT.keySet());
    Collections.sort(v);
    for (int i = 0; i < v.size(); i++)
         Integer key = (Integer) v.get(i);     
         String str = (String) showHT.get(key).toString();
         out.println(key + ": " +  str);
    }How can I do the sorting by id, last name, first name, and age?
    Thank you.

    Given your "design", it is trivial to sort by id -- use a TreeMap .
    Beyond that, you're going to have to face a basic fact: your design sucks. You are abusing Strings.
    You need to:
    1. Define a Person class
    2. Define multiple Person Comparators
    At that point you are essentially done.
    [http://java.sun.com/docs/books/tutorial/collections/algorithms/index.html#sorting]
    edit: or did I misread your vague code snippet? What type is person?

  • 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

  • Differences between standard structured sorted hashed internal tables.

    can any one elobrate the differences among them with simple examples.
    why hashed table serch is faster...what happens if list is not sorted...explain the scenarios best suitable ..when we go for what kinda tables...

    <a href="http://www.sap-img.com/abap/what-are-different-types-of-internal-tables-and-their-usage.htm">refer this link for details</a>
    <a href="http://www.geekinterview.com/question_details/1498">also refer this</a>
    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb366d358411d1829f0000e829fbfe/content.htm">also this- SAP Help</a>
    regards,
    srinivas

  • Examples of sorted hashed  internal tables

    Hello friends
    Can someone give me an example code in which sorted tables and hashed tables have been used.
    Regards

    hi Surya,
    Sorted tables
    This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHERE condition.
    REPORT ZREPORT_SORTED1.
    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.
    The output is:
    SY-SUBRC =    0
    SY-TABIX =       3
             0        9
    REPORT ZREPORT_SORTED2.
    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.
    READ TABLE ITAB WITH KEY COL2 = 16  TRANSPORTING NO FIELDS.
    WRITE:   'SY-SUBRC =', SY-SUBRC,
           / 'SY-TABIX =', SY-TABIX.
    The output is:
    SY-SUBRC =    0
    SY-TABIX =       4
    Hashed tables
    This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.
    REPORT ZREPORT_HASHED1.
    DATA: BEGIN OF LINE,
    COL1 TYPE I,
    COL2 TYPE I,
    END OF LINE.
    DATA ITAB LIKE HASHED 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.
    LINE-COL1 = 2. LINE-COL2 = 3.
    READ TABLE ITAB FROM LINE INTO LINE COMPARING COL2.
    WRITE: 'SY-SUBRC =', SY-SUBRC.
    SKIP.
    WRITE: / LINE-COL1, LINE-COL2.
    The output is:
    SY-SUBRC =    2
             2        4
    REPORT ZREPORT_HASHED2.
    DATA: BEGIN OF LINE,
    COL1 TYPE I,
    COL2 TYPE I,
    END OF LINE.
    DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.
    FIELD-SYMBOLS <FS> LIKE LINE OF ITAB.
    DO 4 TIMES.
      LINE-COL1 = SY-INDEX.
      LINE-COL2 = SY-INDEX ** 2.
    INSERT LINE INTO TABLE ITAB.
    ENDDO.
    READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING <FS>.
    <FS>-COL2 = 100.
    LOOP AT ITAB INTO LINE.
      WRITE: / LINE-COL1, LINE-COL2.
    ENDLOOP.
    The output is:
             1        1
             2      100
             3        9
             4       16
    Regards
    vijay

  • Primary key constraint for index-organized tables or sorted hash cluster

    We had a few tables dropped without using cascade constraints. Now when we try to recreate the table we get an error message stating that "name already used by an existing constraint". We cannot delete the constraint because it gives us an error "ORA-25188: cannot drop/disable/defer the primary key constraint for index-organized tables or sorted hash cluster" Is there some sort of way around this? What can be done to correct this problem?

    What version of Oracle are you on?
    And have you searched for the constraint to see what it's currently attached to?
    select * from all_constraints where constraint_name = :NAME;

  • Internal Table Types (Standard, Sorted, Hashed)

    Hi all,
    I wonder about using internal table types. I always work with standard table type. I don't know when i have to use the standard, sorted or hashed itab type. Is there limits for line counts of types, like over 200.000 lines use hashed table type etc. ? I need performance improvements for itabs.
    Thx,

    the terminology of internal tables is unfortunately quite confusing:
    internal tables use 'index' for the row number of the line in the table, if you know then you can access it directly. It is actually the sy-tabix variable which you have to know.
    Things which are called index on the database are called keys, i.e. the sorted primary key of a SORTED table or the hashed primary key of a HASHED table (the technical realization is actually called index).
    With the newest basis release (7.02 or 7.20) there are also secondary keys possible on internal tables, for all 3 types.
    Siegfried

  • What is the difference between standard,sorted and hash table

    <b>can anyone say what is the difference between standard,sorted and hash tabl</b>

    Hi,
    Standard 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 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 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.
    Regards,
    Ferry Lianto

  • Sorted and hashed tables

    what happens when duplicate entries are present in sorted and hashed tables?

    Hi,
    Sorted internal tables can be of two types:
    unique or non unique.
    If u enter duplicate records in Sorted tables with unique  it will show error.
    If u enter duplicate records in Sorted tables with  non-unique key it will not show error.
    Hashed tables are with only unique key
    so no way to enter the duplicate records.
    for more information see the following link
    http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb35de358411d1829f0000e829fbfe/content.htm
    Reward if helpful.
    Jagadish

  • Displaying graphical representation of data in hash tables as bar chart?

    I want to be able to display results in my hash table as a bar chart i don't know how to do it could someone help me I've looked through tutorials couldn't find any information that actually helped.
    In my program it doesnt allow matching the capital and small letters
    so for instance if I already have Mike it allows for me to input mike in again so there are 2 Mikes.
    I also want to do a simple user interface the tutorial for it is not simple to understand could any one tell me how to create a simple user interface like putting a button into a place wher i want it to be.
    im not asking anyone to do it for me i just want people to show me how to do it
    thank you
    Edited by: Tek_Hedef on Dec 1, 2007 4:30 AM

    Thanks for the ideas pal but I did have a go at it but my bit of code is making it crash but i removed it now so here's what I have so far
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class StudentDetails extends JFrame implements ActionListener
         private JTextField StudentNameTxt, StudentMarkTxt;
        private JButton DeleteStudentDetailsBtn, DisplayAllStudentsBtn, SearchStudentBtn, FailedStudentsBtn, PassedStudentsBtn, DistinctionStudentsBtn, AddStudentDetailsBtn, ExitBtn;
        private JPanel DisplayStudentDetailsPnl;
        private JLabel StudentNameLbl, StudentMarkLbl;
        private JTextArea DisplayResultsTxt;
        private Hashtable StudentDetailsTbl;
        private String StudentName, StudentMark;
        public static void main(String[] args)
            StudentDetails frame = new StudentDetails();
             frame.setSize(600,600);
            frame.createGUI();
            frame.setVisible(true);
        public void display(JPanel DisplayStudentDetailsPnl)
            Graphics paper = DisplayStudentDetailsPnl.getGraphics();
            paper.setColor(Color.white);
            paper.fillRect(0, 0, 500, 500);
            paper.setColor(new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255) ));
        private void createGUI()
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            Container window = getContentPane();
            window.setLayout(new FlowLayout());
            StudentDetailsTbl = new Hashtable();
            StudentNameLbl = new JLabel("Student Name");
            window.add(StudentNameLbl);
            StudentNameTxt = new JTextField(15);
            window.add(StudentNameTxt);
            StudentMarkLbl = new JLabel("Student Mark");
            window.add(StudentMarkLbl);
            StudentMarkTxt = new JTextField(3);
            window.add(StudentMarkTxt);
            AddStudentDetailsBtn = new JButton("Add Student and Mark");
            window.add(AddStudentDetailsBtn);
            AddStudentDetailsBtn.addActionListener(this);
            DeleteStudentDetailsBtn = new JButton("Delete Student");
            window.add(DeleteStudentDetailsBtn);
            DeleteStudentDetailsBtn.addActionListener(this);
            DisplayAllStudentsBtn = new JButton("Display all Students and Marks");
            window.add(DisplayAllStudentsBtn);
            DisplayAllStudentsBtn.addActionListener(this);
            SearchStudentBtn = new JButton("Search Student");
            window.add(SearchStudentBtn);
            SearchStudentBtn.addActionListener(this);
            FailedStudentsBtn = new JButton("Students which Failed");
            window.add(FailedStudentsBtn);
            FailedStudentsBtn.addActionListener(this);
            PassedStudentsBtn = new JButton("Students which Passed");
            window.add(PassedStudentsBtn);
            PassedStudentsBtn.addActionListener(this);
            DistinctionStudentsBtn = new JButton("Students with Distinction");
            window.add(DistinctionStudentsBtn);
            DistinctionStudentsBtn.addActionListener(this);
            ExitBtn = new JButton("Exit");
            window.add(ExitBtn);
            ExitBtn.addActionListener(this);
            DisplayResultsTxt = new JTextArea();
            DisplayResultsTxt.setPreferredSize(new Dimension(200, 200));
            DisplayResultsTxt.setBackground(Color.white);
            window.add(DisplayResultsTxt);
            DisplayResultsTxt.enable(false);
        public void actionPerformed (ActionEvent e)
             if (e.getSource()== AddStudentDetailsBtn)
                  StudentName = StudentNameTxt.getText();
                   StudentMark = StudentMarkTxt.getText();
                  DisplayResultsTxt.setText("");
                  StudentDetailsTbl.put(StudentName, StudentMark);
                Enumeration enumStudentName = StudentDetailsTbl.keys();
                Enumeration enumStudentMark = StudentDetailsTbl.elements();
                String[] keys = (String[]) StudentDetailsTbl.keySet().toArray(new String[0]);       
                Arrays.sort(keys); 
                    for (String key : keys)
                         DisplayResultsTxt.append(key + " : " + StudentDetailsTbl.get(key)+ "\n");
                    StudentNameTxt.setText("");
                    StudentMarkTxt.setText("");
             if (e.getSource() == DeleteStudentDetailsBtn )
             if (StudentDetailsTbl.containsKey(StudentNameTxt.getText().trim()))
                  DisplayResultsTxt.setText("");     
                  String txt = StudentNameTxt.getText();
                Enumeration enumStudentName = StudentDetailsTbl.keys()  ;                   
                    String currentelement = (String)enumStudentName.nextElement();
                     StudentDetailsTbl.remove(txt);
                     DisplayResultsTxt.append(txt + " has been deleted");  
            if (e.getSource() == SearchStudentBtn)
            if (StudentDetailsTbl.containsKey(StudentNameTxt.getText().trim()))
                 String txt = StudentNameTxt.getText();
                 String result;
                 DisplayResultsTxt.setText("");
                 Enumeration enumStudentName = StudentDetailsTbl.keys();
                Enumeration enumStudentMark = StudentDetailsTbl.elements();
                   while (enumStudentName.hasMoreElements())
                        String currentelement = (String)enumStudentName.nextElement();
                    result = (StudentDetailsTbl.get(currentelement).toString());
                        if (txt.equals(currentelement))
                             DisplayResultsTxt.append(currentelement + " " + result);
                        else JOptionPane.showMessageDialog(null, "Student Name could not be identified");
            if (e.getSource() == DisplayAllStudentsBtn)
                  DisplayResultsTxt.setText("");
                 Enumeration enumStudentName = StudentDetailsTbl.keys();
                Enumeration enumStudentMark = StudentDetailsTbl.elements();
                while (enumStudentName.hasMoreElements())
                DisplayResultsTxt.append(enumStudentName.nextElement()+ " " + enumStudentMark.nextElement()+ "\n");
            if (e.getSource() == PassedStudentsBtn)
                 DisplayResultsTxt.setText("");
                 Enumeration enumStudentName = StudentDetailsTbl.keys();
                Enumeration enumStudentMark = StudentDetailsTbl.elements();
                while (enumStudentName.hasMoreElements())
                     int Mark = Integer.parseInt((String)enumStudentMark.nextElement());
                     String Name = (String)enumStudentName.nextElement();
                     if (Mark >=40)
                          DisplayResultsTxt.append(Name + " " + Mark + "\n");
            if (e.getSource() == FailedStudentsBtn)
                 DisplayResultsTxt.setText("");
                 Enumeration enumStudentName = StudentDetailsTbl.keys();
                Enumeration enumStudentMark = StudentDetailsTbl.elements();
                while (enumStudentName.hasMoreElements())
                     int Mark = Integer.parseInt((String)enumStudentMark.nextElement());
                     String Name = (String)enumStudentName.nextElement();
                     if (Mark <40)
                          DisplayResultsTxt.append(Name + " " + Mark + "\n");
            if (e.getSource() == DistinctionStudentsBtn)
                 DisplayResultsTxt.setText("");
                 Enumeration enumStudentName = StudentDetailsTbl.keys();
                Enumeration enumStudentMark = StudentDetailsTbl.elements();
                while (enumStudentName.hasMoreElements())
                     int Mark = Integer.parseInt((String)enumStudentMark.nextElement());
                     String Name = (String)enumStudentName.nextElement();
                     if (Mark >=75)
                          DisplayResultsTxt.append(Name + " " + Mark + "\n");
    }

  • How about use partial key to loop at a hashed table?

    Such as I want to loop a Internal table of BSID according to BKPF.
    data itab_bsid type hashed table of BSID with unique key bukrs belnr gjahr buzid.
    Loop at itab_bsid where bukrs = wa_bkpf-bukrs
                              and    belnr  = wa_bkpf-belnr
                              and    gjahr  = wa_bkpf-gjahr.
    endloop.
    I know if you use all key to access this hashed table ,it is certainly quick, and my question is when i use partial key of this internal hashed table to loop it, how about its performance.
    Another question is in this case(BSID have many many record) , Sorted table and Hashed table , Which is better in performance.

    You can't cast b/w data reference which l_tax is and object reference which l_o_tax_code is.
    osref is a generic object type and you store a reference to some object in it, right? So the question is: what kind of object you store there? Please note - this must be an object reference , not data reference .
    i.e
    "here goes some class
    class zcl_spfli definition.
    endclass.
    class zcl_spfli implementation.
    endclass.
    "here is an OBJECT REFERENCE for it, (so I refer to a class) i.e persistent object to table SPFLI
    data oref_spfli type ref to zcl_spfli.
    "but here I have a DATA REFERENCE (so I refer to some data object) i.e DDIC structure SPFLI
    data dref_spfli type ref to spfli.
    So my OSREF can hold only oref_spfli but it not intended for dref_spfli . That's why you get this syntax error. Once you have stored reference to zcl_spfli in osref then you will be able to dereference it and access this object's attributes.
    data: osref type osref.
    create object osref_spfli.
    osref = osref_spfli.
    "now osref holds reference to object, you can deference it
    oref_spfli ?= osref.
    osref_spfli->some_attribute = ....
    OSREFTAB is just a table whose line is of type OSREF (so can hold multiple object references - one in each line).
    Regards
    Marcin

  • How do I use Get-ADUser to get just the Managers attribute? And then get rid of duplicates in my array/hash table?

    Hello,
          I am trying to just get the Managers of my users in Active Directory. I have gotten it down to the user and their manager, but I don't need the user. Here is my code so far:
    Get-ADUser-filter*-searchbase"OU=REDACTED,
    OU=Enterprise Users, DC=REDACTED, DC=REDACTED"-PropertiesManager|SelectName,@{N='Manager';E={(Get-ADUser$_.Manager).Name}}
    |export-csvc:\managers.csv-append 
    Also, I need to get rid of the duplicate values in my hash table. I tried playing around with -sort unique, but couldn't find a place it would work. Any help would be awesome.
    Thanks,
    Matt

    I would caution that, although it is not likely, managers can also be contact, group, or computer objects. If this is possible in your situation, use Get-ADObject in place of Get-ADUser inside the curly braces.
    Also, if you only want users that have a manager assigned, you can use -LDAPFilter "(manager=*)" in the first Get-ADUser.
    Finally, if you want all users that have been assigned the manager for at least one user, you can use:
    Get-ADUser
    -LDAPFilter "(directReports=*)" |
    Select @{N='Manager';E={ (Get-ADUser
    $_.sAMAccountName).Name }}
    -Unique | Sort Manager |
    Export-Csv .\managerList.csv -NoTypeInformation
    This works because when you assign the manager attribute of a user, this assigns the user to the directReports attribute of the manager. The directReports atttribute is multi-valued (an array in essence).
    Again, if managers can be groups or some other class of object (not likely), then use Get-ADObect throughout and identify by distinguishedName instead of sAMAccountName (since contacts don't have sAMAccountName).
    Richard Mueller - MVP Directory Services

Maybe you are looking for

  • NOKIA OVI STORE SUPPORT - INEFFICIENT

    DEAR ALL I HAD DONE A PURCHASE AND THIS IS THE BELOW WHAT I GOT FROM THE SUPPORT - NOTHING YET YOU CAN KNOW IT FROM THE NUMBER OF "RE'S" ON THE SUBJECT OF THE EMAILS. GET ME THE LINK TO THE PROGRAM, BECAUSE I PAID FOR IT I WILL NEED TO DOWNLOAD IT. h

  • No files opened in Acrobat X when opened via JavaScript (as ActiveXObject)

    Hi together In a web application (ASP.Net) we developed, the customers may open, edit and save pdf files. The files are stored on a network drive which is connected over a vpn tunnel. To edit the selected files, Acrobat is opened by a JavaScript from

  • HP w1907v

    Hi, When I start my computer my monitor says VGA imput: NO SIGNAL  or something and after goes to sleep. I dont know my computer specs, but when I connect my monitor with my laptop the monitor works can someone tell how to fix it. My PC uses windows

  • I want to upgrade from CS5.5 to CS6

    I really don't want 'people' I want suppot

  • How to resize pictures in iPhoto09 ?

    Hi there, How to resize the pictures in iPhoto09 ? The picture that I imported into iPhoto09 is too big for my liking. How can I resoze & make it smaller ? Thanks