Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Logic needed

Former Member
0 Likes
876

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
846

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.

8 REPLIES 8
Read only

Former Member
0 Likes
846

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

Read only

0 Likes
846

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

Read only

Former Member
0 Likes
846
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

Read only

Former Member
0 Likes
847

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.

Read only

Former Member
0 Likes
846

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.

Read only

0 Likes
846

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

Read only

Former Member
0 Likes
846

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.

Read only

0 Likes
846

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?