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

Comparing Itab to DB

Former Member
0 Likes
1,028

Hello,

I have one internal table and with same structure of view.

I want to compare internal table to DB table.

Want to filter records which doesnt exist in DB table.

Can any one help me how to do it?

Regards,

Chitra R.

6 REPLIES 6
Read only

former_member386202
Active Contributor
0 Likes
843

Hi,

Select data from that database table into internal table.

Loop on first internal table and read this internal table if sy-subrc is no equal to zero then delete record from first internal table.

Regards,

Prashant

Read only

Former Member
0 Likes
843

ya do one thing..

just do a SELECT using for all entries comparing the primary key fields into another internal table..

For example internal table contains 10 records where as only 5 match with view data

SELECT *

FROM <VIEW>

INTO TABLE ITAB_NEW

for all entries in ITAB_OLD

WHERE key1 eq itab_old-key1

and key2 eq itab_old-key2....

Now you will get matching 5 records only into ITAB_NEW>.

hope ur prob solved...

dont forget to check ITAB_OLD[] is not initial before SELECT usign for all entries..

Read only

Former Member
0 Likes
843

select * from databasetable into table itab2.

loop at itab1.

read table itab2 with key field = itab1-field.

if sy-subrc <> 0.

delete itab1 index sy-tabix.

endif.

endloop.

Read only

0 Likes
843

Thanks for the solution.

but select * from DB into itab.

incase more than 60k records from ur DB.then how will you fetch all records to our internal table?

Read only

Former Member
0 Likes
843

Hi,

fetch the data from DB table into ITAB1

then compare the ITAB and ITAB1 like

IF ITAB[] = ITAB1[]

Regards,

Omkar.

Read only

Former Member
0 Likes
843

Hi,

Fetch record from database one at a time in the work area.

Use READ command to read the internal table with the condition as the values fetched in the workarea(see syntax of READ).

If sy-subrc is not zero .Delete that record.

But this will result in hiting the database repeatedly.

Deserve Reward.

Gaurav