07-24-2008 6:55 AM
Hi there,
I know that there is a way of modifying a record in an internal table while looping. But is it possible to modify a record in itable without a loop? And only one field should only be modified. I want to modify a record in itab. I want to modify the customer number in itab, where the customer number is 9.
In sql it is
update table set cusno = 0 where cusno = 9.
Is it possible in an internal table
07-24-2008 6:58 AM
hi,
You can use the modify statement after the read statement for your requirement.
read table itab where field = 9.
if sy-subrc eq 0.
modify itab transporting field.
endif.
Regards,
Veeresh
07-24-2008 6:59 AM
Hi Katrina Dy,
Write read statement first and then write update sytax.
Read table itab into fs_tab with key cusno = 9.
if sy-subrc eq 0.
itab-cusno = 0.
modify ifab from fs_tab.
endif.
Regards,
Mahi.
07-24-2008 7:03 AM
Try this way:
1. Read table (itab) into wa_itab with key customer = xxx.
2. If sy-subrc = 0, get sy-tabix (index of that record).
3. set the changes that you want to make in wa_itab.
4. Modify (itab) index sy-tabix from wa_itab.
07-24-2008 7:04 AM
07-24-2008 7:08 AM
Hi Katrina,
Try to use index for modifying internal table.To modify the internal table without loop can be done through READ Statement where you can use your key fields and get the record and also index value and hence modify the table.
Thanks
Sudharshan
07-24-2008 7:11 AM
hey
am not very clear but i can send you the sample code.
Just refer to this:
SELECT carrid
connid
price
FROM sflight
UP TO 10 ROWS
INTO TABLE itab.
READ TABLE itab INDEX 1.
itab-price = itab-price - 10.
MODIFY itab INDEX 1.
Hope this helps.
Incase you dont know the index , just store the sy-tabix value into another variable say v_tabix and then modify it. The sy-tabix value must be stored immediately after you write the read statement.
I dont know any other way
hope this helps.
regards,
Ravi
07-24-2008 7:39 AM
Read table itab into wa_tab with key cusno = 9.
If sy-subrc eq 0.
wa_tab-cusno = 0.
modify ifab from wa_tab index sy-tabix.
Endif.
07-24-2008 7:48 AM
If you don't use BINARY SEARCH or a sorted table, then you can also make the full loop, there is nt much difference.
And it is usually not posible to use READ with index because the index is not known.
But you should keep the index after the READ and do the MODIY with index.
Siegfried
07-24-2008 7:56 AM
hello,
one good way is to read that record with key values and then write a modify stmt transporting the value to be modified with where cause.......
int_tab
F1 F2 F3
A C 5
B E 3
D F 1
so now if u want to modify F3 field from int_tab with value 22 where F1 = B and F2 = E
then
read table int_tab with key F1 = B
F2 = E.
if sy-subrc = 0.
int_tab-F3 = 22.
modify int_tab trnsporting F3 where F1 = B
and F2 = E.
Endif.
Mark the post answered once ur problem is solved ....