ABAPINSERT_ITAB - INSERT ITAB
RFUMSV00 - Advance Return for Tax on Sales/Purchases BAL_S_LOG - Application Log: Log header dataThis documentation is copyright by SAP AG.
INSERT itab
Syntax
INSERT line_spec INTO itab_position[result].
Effect
This statement adds one or more rows line_specto a position itab_positionin an internal table. The position can be specified using the primary table key or the table index.resultcan be used to set a reference as a field symbol or data reference to the inserted row when inserting a single row.
At the insertion of a row, all existing unique table keys are checked. This can be aprimary table key and multiple uniquesecondarytable keys. The system handles any duplicates of the various key according to the following hierarchy:
- If an attempt is made to insert a single row via a primary key that would result in duplicates that affected the unique primary key, no row is inserted and sy-subrc is set to 4.
- If an attempt is made to insert a single row via the key or the index that would result in duplicates that affected the unique primary key, a treatable exception of the CX_SY_ITAB_DUPLICATE_KEY class is raised.
- If an attempt to insert multiple rows as a block would result in duplicates that affected the unique primary or secondary keys, a runtime error occurs.
System Fields
| sy-subrc | Meaning |
| 0 | One or more lines were inserted. |
| 4 | No row was inserted because either a row of the same unique key already existed wheninserting single rows using the primary key or the specified index was greater than the current number of rows plus one when inserting the rows using the table index. |
Note
The administration of an unique secondary table key is updated immediately(directupdate) and the administration of a non-unique secondary table key is updated at the next explicit use of the secondary table key(lazyupdate). The runtime costs for the creation or updating of a non-unique secondary table key are therefore first incurred when it is first used. (SeeInternal Tables, Deleting Rows Using Keys).
Example
Insertion of single rows using the table index in astandard table int_tab and insertion of references to these rows using the table key in ahashedtable ref_tab. The output in the LOOPloops result in the numbers 10 to 1 for int_tab and the numbers 1 to 10 for ref_tab.
DATA: int TYPE i,
dref TYPE REF TO i.
DATA: int_tab LIKE STANDARD TABLE OF int,
ref_tab LIKE HASHED TABLE OF dref
WITH UNIQUE KEY table_line.
DO 10 TIMES.
INSERT sy-index
INTO int_tab INDEX 1
REFERENCE INTO dref.
INSERT dref
INTO TABLE ref_tab.
ENDDO.
LOOP AT int_tab INTO int.
WRITE / int.
ENDLOOP.
SKIP.
LOOP AT ref_tab INTO dref.
WRITE / dref->*.
ENDLOOP.
Exceptions
Catchable Exceptions
- Cause: Duplicate key values in unique secondary key
Runtime Error: ITAB_DUPLICATE_KEY
Non-Catchable Exceptions
- Cause: When inserting a row set, entries with an identical key occurred (target table is defined by UNIQUE).
Runtime Error: ITAB_DUPLICATE_KEY - Cause: Violation of the sort order by using an INSERT with index on a sorted table.
Runtime Error: ITAB_ILLEGAL_SORT_ORDER - Cause: Invalid index value (<= 0) for a specification of FROM, TO, or INDEX.
Runtime Error: TABLE_INVALID_INDEX
Addresses (Business Address Services) RFUMSV00 - Advance Return for Tax on Sales/Purchases
This documentation is copyright by SAP AG.
Length: 6591 Date: 20120522 Time: 233239 triton ( 164 ms )






