![]() ![]() Well now as of ABAP 7.2 can declare secondary keys for internal tables. OK, back to internal tables, traditionally, if you wanted to read an internal table in two different ways (e.g.,looking for a material by Material Number or by Reference Number), then you either had to keep sorting the table just before a read, or have two identical tables sorted differently. Why do we create a custom index or z-index? For performance… we recognize that a table could be queried in more ways then just by the primary key, so we setup customer indexes that we believe will be used by the Database Optimizer when determining the access path and thus make the query performant. Equally, a runtime error occurs if you violate the sort order of a sorted table by appending to it.Using Secondary Keys to Access Internal Tables in ABAP 7.4Īll of us who have been developing in ABAP at one time or another have created a custom index on a database table. A runtime error occurs if you attempt to add a duplicate entry to a sorted table with a unique key. ![]() Then the new line is inserted before the current line idx is implicitly set to sy-tabix.Īppending lines to standard tables and sorted tables with a non-unique key works regardless of whether lines with the same key already exist in the table. Without the INDEX addition, you can only use the above statement within a LOOP. When the system successfully adds a line to the table, sy-subrc is set to 0. If the table has less than idx - 1 lines, the new line cannot be inserted, and sy-subrc is set to 4. If the table contains idx -1 lines, the new line is added after the last line. After the insertion, the new entry has the index idx and the index of the following lines is incremented by 1. If you use the INDEX option, the new line is inserted before the line that has the index idx. INITIAL LINE inserts an initialized blank line suitable for the type. If you use wa, the system adds a new line to the internal table itab and fills it with the contents of the work area. Line is either a work area wa that is convertible to the line type, or the expression INITIAL LINE. To insert a line into an index table, use the statement: Single lines are inserted into a sorted internal table. line-weight = '75.00'.INSERT line INTO TABLE itab. line-weight = '60.00'.INSERT line INTO TABLE itab. line-weight = '50.00'.INSERT line INTO TABLE itab. line-weight = '95.00'.INSERT line INTO TABLE itab. line-weight = '45.00'.INSERT line INTO TABLE itab. line-weight = '80.00'.INSERT line INTO TABLE itab. The table is inserted into the internal hash administration according to the table key.ĭATA: BEGIN OF line, land(3) TYPE c, name(10) TYPE c, age TYPE i, weight TYPE p DECIMALS 2, END OF line.ĭATA itab LIKE SORTED TABLE OF line WITH NON-UNIQUE KEY land name age weight. The runtime for the operation increases logarithmically with the number of existing table entries. If the key is non-unique, duplicates are inserted above the existing entry with the same key. The line is inserted into the table according to the table key. The statement works in the same way as the specific statement APPEND for appending lines. ![]() The line is appended to the end of the internal table. Lines are added to internal tables as follows: ![]() If the internal table has a unique key, lines whose key already exists in the table will not be inserted and sy-subrc is set to 4. The work area must be compatible because the fields in the table key must be filled from fields of the correct type. Line is either a work area that is compatible with the line type, or the expression INITIAL LINE. To add a line to an internal table, use the statement: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |