

The internal table definition could be as shown below. But, on the other hand, secondary keys also incur additional administration costs due to memory consumption and run-time.įor example, lets create a secondary index into the internal table IT_MARA for the column BISMT, this is just like having a secondary Z- index on BISMT in the database table definition. The SAP Help states that using the secondary key could increases read access performance significantly. 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. Latest notes:If a conflict with existing primary or secondary table keys occurs, this always raises a non-handleable exception when multiple rows are appended.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. The additions FROM idx1 and TO idx2 have, in relation to jtab, the same syntax and effect as for LOOP. The order in which the rows are taken is the same as for the statement LOOP and can also be influenced by specifying a table key keyname after USING KEY. The row type of jtab can be incompatible with the row type of the internal table itab and it is converted to the row type of the target table (if necessary), in accordance with the conversion rules. The inserted rows are sequentially taken from the table jtab. LINES OF jtab What does it do? The rows of an internal table jtab are added as a block. APPEND INITIAL LINE TO itab ASSIGNING line>. This means that initial rows can be processed directly. Example ABAP Coding Attaching an initial row which is also linked to a field symbol by the ASSIGNING addition. INITIAL LINE What does it do? A new row is added in which every component contains the type-specific initial value. INITIAL LINE APPEND ABAP Alternative 2.DATA: int TYPE i, itab LIKE SORTED TABLE OF int WITH UNIQUE KEY table_line. Example ABAP Coding Appending square numbers to a sorted table with elementary row type.

The statement then uses the header line as the work area implicitly.

With the exception, an obsolete short form is possible where wa TO can be omitted, if the internal table has a header line itab with the same name.

Specifying a calculation expression for wa is usually only a good idea for elementary row types. In the case of a conflict with a unique secondary table key, a handleable exception of the class CX_SY_ITAB_DUPLICATE_KEY is raised. Latest notes:If a conflict occurs with an existing unique primary table type, this raises a non-handleable exception when appending a single row. If an arithmetic expression is specified for wa, the row type of the internal table is respected when determining the calculation type. wa may be incompatible with the row type of the internal table and, if necessary, is converted to the row type in accordance with the conversion rules. wa What does it do? A new row is appended to which the content of the work area wa is assigned. LINES OF jtab What does it do? Either a work area wa, an initial row INITIAL LINE, or multiple rows of an internal table jtab can be appended.
#Sap append lines of itab to itab code#
Get Example source ABAP code based on a different SAP table ABAP Statement APPEND - line_spec Short Reference ABAP Syntax ABAP_KEY.
