sapdev logo background
sapdev logo sapdev logo
Comments

ABAP MODIFY ITAB INDEX Statement syntax, information and example SAP source code



Return to Statement index



MODIFY itab - index

Short Reference

ABAP Syntax ... { itab INDEX idx [USING KEY keyname ] }
| { itab [USING KEY loop_key]} ... .

ABAP_ALTERNATIVES:
1 ... itab INDEX idx [USING KEY keyname]
2 ... itab [USING KEY loop_key]

What does it do? These alternatives specify the rows to be changed using the specification of a row number relating to a table index.

ABAP_ALTERNATIVE_1 ... itab INDEX idx

ABAP_ADDITION:
... USING KEY keyname

What does it do? If the INDEX addition is used, the MODIFY statement modifies the row of the row number specified in idx with respect to a table index. idx is a numerical expression position
of the operand type i . If idx contains a value of 0 or less, an exception is raised that cannot be handled.
If the addition USING KEY is not used, the addition INDEX
can only be used with index tables and determines the row to be modified from the primary table index .
If a row specified using INDEX is modified without the addition
TRANSPORTING , then all components of the row are transported. If at the same time it is statically determinable that write-protected
secondary table keys would be overwritten by this, this leads to a syntax error. If it can only be determined at runtime, the corresponding runtime error occurs.
If the components of a primary sorted table key are modified in a row specified using INDEX , however, a runtime error occurs only if the value of the component changes.

Latest notes: The addition INDEX can also be positioned after
FROM wa .

Example ABAP Coding Conversion of an airline's local currency to euro in internal table scarr_tab by accessing the index.
PARAMETERS p_carrid TYPE scarr-carrid.

DATA scarr_tab TYPE SORTED TABLE OF scarr
WITH UNIQUE KEY carrid.

DATA: idx TYPE sy-tabix,
scarr_wa TYPE scarr.

SELECT *
FROM scarr
INTO TABLE scarr_tab.

READ TABLE scarr_tab
WITH TABLE KEY carrid = p_carrid
TRANSPORTING NO FIELDS.

idx = sy-tabix.

scarr_wa-currcode = 'EUR'.

MODIFY scarr_tab INDEX idx FROM scarr_wa
TRANSPORTING currcode.

ABAP_ADDITION ... USING KEY keyname

What does it do? If the addition USING KEY is used, a table key can be declared in keyname to declare the table index to be used explicitly.
If the table has a sorted secondary key , this can be specified in keyname . The row to be modified is then determined from its secondary table index . You cannot declare a secondary hashed key .
If the primary table key is specified under the name primary_key , the table must be an index table, and the behavior is the same as when USING KEY is not specified.
Latest notes: If a sorted secondary key exists, the INDEX addition can be used for all table types, if USING KEY is used.

ABAP_ALTERNATIVE_2 ... itab

ABAP_ADDITION:
... USING KEY loop_key

What does it do? This variant is only possible within a LOOP across the same internal table. The current table row of the LOOP is modified implicitly. If the addition USING KEY is specified in LOOP , then the variant USING KEY loop_key must be specified for this variant.
If the current rows were already deleted in the same loop pass, then the behavior is undefined.
This variant is not allowed outside of a LOOP and raises a warning in the syntax check, if the check cannot detect (statically) its presence in a loop.
Latest notes: We do not recommend that you use this alternative. Instead, use the INDEX addition to specify the row number explicitly.

ABAP_ADDITION ... USING KEY loop_key

What does it do? This addition is required if the table key used by the LOOP is specified explicitly in the statement LOOP . It states explicitly that the current table row is modified by the LOOP
. No other key can be specified apart from the predefined name loop_key . If no explicit table key is specified for LOOP , then the addition USING KEY loop_key
is optional.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




MODIFY_ITAB
MODIFY_ITAB_MULTIPLE




comments powered by Disqus