‎2006 Dec 20 8:43 PM
Hi-everyone I want to update a field in an internal table can anyone suggest me the procedure and syntax.
Thanks in advance.
‎2006 Dec 20 8:45 PM
Hello,
U can use the
ITAB-FIELD10 = 'YYYY'.
MODIFY ITAB <b>INDEX 1 or from wa.</b>
If u r using
LOOP AT ITAB.
ITAB-FIELD10 = 'YYYY'.
MODIFY ITAB.
ENDLOOP:
If useful reward.
Vasanth
‎2006 Dec 20 8:45 PM
DATA: W_TABIX TYPE SY-TABIX.
LOOP AT MY_TABLE.
W_TABIX = SY-TABIX.
MY_TABLE-FIELD1 = 'Hello'.
MODIFY TABLE MY_TABLE INDEX W_TABIX
TRANSPORTING FIELD1.
ENDLOOP.
Greetings,
Blag.
‎2006 Dec 20 8:56 PM
Here in this case index is varying...can u suggest anyother way...
Thanks in advance.
‎2006 Dec 20 9:25 PM
Hello,
LOOP AT it2.
it1-field1 = it2-field2. "sales order
MODIFY it1 TRANSPORTING field1
((you can also use a where condition if both the tables have something in common)
WHERE vbeln = it2-vbeln.)
ENDLOOP.
hope this helps.
‎2006 Dec 20 9:00 PM
Hi Nagini,
Use MODIFY statement to update a filed(s) in an internal table.
Check this link to know about MODIFY statement.
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/modify_l.htm
DATA V_TABIX TYPE SY-TABIX.
If you want to change a single statement use MODIFY followed by a READ statement
READ ITAB KEY FIELD MATNR = <MATERIAL>.
IF SY-SUBRC = 0.
ITAB-BSTME = '10'.
MODIFY ITAB INDEX SY-TABIX.
ENDIF.
If you want to change more than one line item the use MODIFY inside in LOOP..ENDLOOP statements.
LOOP ITAB WHRE BSTME < '5'.
V_TABIX = SY-TABIX.
ITAB-BSTME = '10'.
MODIFY ITAB INDEX V_TABIX.
ENDLOOP.
Thanks,
Vinay
‎2006 Dec 20 9:01 PM
Hi Nagini,
Do this way:
<b>Data: zindex like sy-tabix.</b>
<b>Clear zindex.</b>
LOOP AT ITAB.
zindex = sy-tabix.
ITAB-FIELD1 = 'changed'.
MODIFY ITAB index <b>zindex</b>.
CLEAR: ITAB, zindex.
ENDLOOP.
Regards,
Vivek
‎2006 Dec 20 9:36 PM
HI,
When you process an internal table object, you must distinguish between the following two cases:
<b>Operations on Entire Internal Tables</b>
http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb3653358411d1829f0000e829fbfe/content.htm
<b>Operations on Individual Lines</b>
The following are typical operations involving single lines of a table:
Filling a table line by line
Reading a table line by line
Modifying individual lines
Deleting individual lines
Influence of the Table Type
When working with single table lines, we must distinguish between the operators that are possible for all table types, and those that are only possible with index tables. Index tables (standard and sorted tables) have an internal index, making linear access possible. Hashed tables have no linear index. Consequently, only key access is possible. The operations that are permitted for all table types do not use indexes. They can also be used in procedures or with field symbols , where the internal table type is not fully typed. These operations are known as generic operations.
The statements used to access lines of any type of table differ from those used to access index tables mainly through the TABLE addition following the corresponding keyword. For example, you would use MODIFY to change lines in index tables, but MODIFY TABLE to change lines in any type of table.
Access methods
There are two ways to access a single table entry:
Access Using a Work Area
When you access individual table entries using a work area, you are not working directly with the data in the table. Instead, you work with another data object as a work area. The work area is an interface to the entries in the internal table, and must be convertible into the line type of the internal table. The most efficient working method is to use a work area compatible with the line type of the internal table. When you read data from a table record, the data you are reading overwrites the current contents of the work area. You can then use this data in the program. When you write data to the internal table, this must first be placed in the work area. The system then transfers it from the work area to the appropriate table entry. Data transfer follows the rules of assigning data using MOVE.
If the internal table has a header line, you can use it as the work area. The ABAP statements that you use to access individual table entries can use the header line implicitly as a work area.
Access Using Field Symbols
If you access an internal table using a field symbol , you do not need to copy the data into a work area. You can assign a line of an internal table to a field symbol. Ideally, the field symbol will have the same type as the line type of the internal table. Once you have assigned the entry to the field symbol, working with the field symbol has exactly the same effect as accessing the corresponding line directly.
<b>Operations for all Table Types</b>
<i>Changing Lines</i>
To change a single line of any internal table, use the MODIFY statement. You can either use the table key to find and change a single line using its key, or find and change a set of lines that meet a certain condition. If the table has a non-unique key and there are duplicate entries, the first entry is changed.
Changing a Line Using the Table Key
To change a single line, use the following statement:
MODIFY TABLE <itab> FROM <wa> [TRANSPORTING <f1> <f 2> ...].
The work area <wa>, which must be compatible with the line type of the internal table, plays a double role in this statement. Not only it is used to find the line that you want to change, but it also contains the new contents. The system searches the internal table for the line whose table key corresponds to the key fields in <wa>.
The system searches for the relevant lines as follows:
Standard tables
Linear search, where the runtime is in linear relation to the number of table entries. The first entry found is changed.
Sorted tables
Binary search, where the runtime is in logarithmic relation to the number of table entries. The first entry found is changed.
Hashed tables
The entry is found using the hash algorithm of the internal table. The runtime is independent of the number of table entries.
If a line is found, the contents of the non-key fields of the work area are copied into the corresponding fields of the line, and SY-SUBRC is set to 0. Otherwise, SY-SUBRC is set to 4. If the table has a non-unique key and the system finds duplicate entries, it changes the first entry.
You can specify the non-key fields that you want to assign to the table line in the TRANSPORTING addition. You can also specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.
For tables with a complex line structure, the usage of the transporting option results in better performance, if the system must not transport unnecessary table-like components.
Changing Several Lines Using a Condition
To change one or more lines using a condition, use the following statement:
<b>MODIFY <itab> FROM <wa> TRANSPORTING <f1> <f 2> ... WHERE <cond>.</b>
This processes all of the lines that meet the logical condition <cond>. The logical condition can consist of more than one comparison. In each comparison, the first operand must be a component of the line structure. If the table lines are not structured, the first operand can also be the expression TABLE LINE. The comparison then applies to the entire line. The work area <wa>, which must be compatible with the line type of the internal table, contains the new contents, which will be assigned to the relevant table line using the TRANSPORTING addition. Unlike the above MODIFY statement, the TRANSPORTING addition is not optional here. Furthermore, you can only modify the key fields of the internal table if it is a standard table. If at least one line is changed, the system sets SY-SUBRC to 0, otherwise to 4.
<b>Operations for Index Tables</b>
Changing Table Lines Using the Index
You can use the MODIFY statement to change lines in tables using their index. There is also a special variant of the WRITE TO statement that you can use to modify standard tables.
Changing Single Lines with MODIFY
To change a line using its index, use the following statement:
MODIFY <itab> FROM <wa> [INDEX <idx>] [TRANSPORTING <f1> <f 2> ... ].
The work area <wa> specified in the FROM addition replaces the existing line in <itab>. The work area must be convertible into the line type of the internal table.
If you use the INDEX option, the contents of the work area overwrites the contents of the line with index <idx>. If the operation is successful, SY-SUBRC is set to 0. If the internal table contains fewer lines than <idx>, no line is changed and SY-SUBRC is set to 4.
Without the INDEX addition, you can only use the above statement within a LOOP. In this case, you change the current loop line <idx> is implicitly set to SY-TABIX.
When you change lines in sorted tables, remember that you must not change the contents of key fields, and that a runtime error occurs if you try to replace the contents of a key field with another value. However, you can assign the same value.
The TRANSPORTING addition allows you to specify the fields that you want to change explicitly in a list. See also Changing Table Entries. If you change a sorted table, you may only specify non-key fields.
Changing Lines Using WRITE TO
You can change lines of standard tables using the following statement:
WRITE <f> TO <itab> INDEX <idx>.
This variant of the WRITE TO statement converts the contents of field <f> to type C and then transfers the resulting character string into the line with index <idx>. If the operation is successful, SY-SUBRC is set to 0. If the internal table contains fewer lines than <idx>, no line is changed and SY-SUBRC is set to 4.
The data type of <f> must be convertible into a character field; if it is not, a syntax or runtime error occurs. The line is always interpreted as a character string, regardless of its actual line type. You can process components in the same way as in the normal WRITE TO statement. You should only use this statement for structured line types if you want to change a single character whose exact position you already know. Another possibility is to use internal tables whose structure is made up of a single character field. Tables of this kind are often used in dynamic programming.
Regards,
Vara
‎2006 Dec 20 10:28 PM