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

compare 2 itab

Former Member
0 Likes
1,190

hi.

Iam having 2 itab's, and i want to compare this 2 itab.

itab1 and itab2 is a structure of CAUFVD ( so approx 300 fields).

itab1 consist of old values and itab2 consist of new values. when iam comapring this two tables the fields the difference should be stored in a new table.

SO is there any function module for this.........

Thanking you.

regards.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,113

Hi!

Try out this one:

CTVB_COMPARE_TABLES

However I think you might code it faster with a line-by-line comparison, within a LOOP.

Regards

Tamá

9 REPLIES 9
Read only

Former Member
0 Likes
1,114

Hi!

Try out this one:

CTVB_COMPARE_TABLES

However I think you might code it faster with a line-by-line comparison, within a LOOP.

Regards

Tamá

Read only

Former Member
0 Likes
1,113

<b>IF itab2[] NE itab1[].

"Records are different

ENDIF.</b>

Read only

Former Member
0 Likes
1,113

Hi Hemant

I am not sure about FM , but you can write a code , which compares line by line and if sy-subrc fails then move the record to internal table which is having similar structure as that of itab1 or 2

Regards

Hemant

Read only

Former Member
0 Likes
1,113

hi,

try this code.

i had a similar application and this code worked fine.

loop at itab1.

read table itab2 with key...(fields which uniquely identify records like - field1 = itab1-field1...).

if sy-subrc <> 0.

move itab1 to itab_new.

append itab_new.

clear itab_new.

endif.

clear itab1.

clear itab2.

endloop.

itab2 is old table and itab1 contains some new/changed values.

hope this gives u some idea.

Read only

0 Likes
1,113

but my itab consist of 411 fields (columns) so how to comapre each fields.......is a structure of (CAUFVDB)

Read only

0 Likes
1,113

don't take all columns only those columns which identify each record...like primary key ...

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,113

sort itab1 by key fields.

sort itab1 by key fields.

Loop at itab1.

read table itab2 with key field.

if sy-subrc <> 0.

append itab1 to new_itab.

endif.

endloop.

hope thi helps you..

Read only

Former Member
0 Likes
1,113

HI,

U can take a temp. table and add rows which u need to compare which are from different tables.

then use DELETE ITAB COMPARING ALL FIELDS.

then describe table temp. if it has one row then fileds are same else they are different.

Read only

Former Member
0 Likes
1,113

Thanks