‎2008 Jul 29 4:23 PM
HI Experts,
I needa logic to update a ZTABLE.
table has 2 primary keys.
ex: pk1 pk2 f1 f2 f3 f4.
i created records like...
pk1 pk2 f1 f2 f3 f4
-
1 2 a b c d
1 3 e f g h
1 4 i j k l
1 5 m n o p
-
now user deletes one of the record and changes other record..... like...
pk1 pk2 f1 f2 f3 f4
-
1 2 a b c d
1 3 e x y z
1 5 m n o p
-
how can i update the ZTable with these updated values.... I am looking at performance wise...
i thought abt deleting all records for PK1 and create again with new records... but i feel this can be performance issue... any idea to achieve this?
Thanks
Giri
‎2008 Jul 29 4:32 PM
Hi,
Instead of deleting the records from the internal table (tab 1) simply set a flag against every record that has been deleted.
Move these records into a separate internal table (tab 2) and delete them from tab1.
Then:
MODIFY dbtab FROM TABLE tab1.
DELETE dbtab FROM TABLE tab2.
‎2008 Jul 29 4:27 PM
hi,
do this way .... Loop through the internal table to modify the record of that index ...
loop at itab.
lv_index = sy-tabix.
.....
modify <ztable> index lv_tabix transporting < modified fields>.
endloop.
delete <ztable> where <conditions>.
Regards,
Santosh
‎2008 Jul 29 5:08 PM
GUys,
thanks for reply,
once user is deleted, i wont get that records anymore.... and what happens when user deltes all records....
then i wont get any record but i need to delete from ZTABLE... i think it is not possible ... i need some key to find which records to delete....
Regards
Giri
‎2008 Jul 29 4:29 PM
UPDATE ZTABLE SET F2 = 'X' ... WHERE pk1 = 1 and pk2 = 2.OR
Use a local structure of type ZTABLE and do a MODIFY to the table.
A
‎2008 Jul 29 4:32 PM
Hi,
Instead of deleting the records from the internal table (tab 1) simply set a flag against every record that has been deleted.
Move these records into a separate internal table (tab 2) and delete them from tab1.
Then:
MODIFY dbtab FROM TABLE tab1.
DELETE dbtab FROM TABLE tab2.
‎2008 Jul 29 5:23 PM
As I said, use a copy of the Ztable and add a "Deletion Flag" field to it. Compare the 2 tables and set the flag for all the deleted records.
‎2008 Jul 29 8:57 PM
Harsha,
how can u comapre 2 internal tables?
both have same number of records and but different values....
is there any parameter to compare two tables?
Giri
‎2008 Jul 29 5:25 PM
Hello Giri,
I suggest you not to use your modified internal table in the UPDATE or MODIFY statements.
Because, some of the lines are not changed in the internal table and even these records are included for modification, which is not suggestible performance wise.
Get all the records that are modified into another internal table and the deleted records into another internal table and use
MODIFY <target> FROM TABLE <itab> .
to modify the records and
DELETE <target> FROM TABLE itab <wa> .
to delete the records
Creating another internal table is better than hitting the database unnecessarily for the unchanged records.
Regards
Indu.
‎2008 Jul 29 6:18 PM
how to compare two table records, for changes?
i believe ur suggestion is good for performace ....
but need some more logic.... for modified records and deleted records...
any simple way to do it instead of lot of loops to achieve this?