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 two dynamic tables

Former Member
0 Likes
1,268

i have two dynamic tables, <fs_t1> and <fs_t2> . they have the same structure. one is a table built from the user uploaded excel sheet and the other is a table built from the database. now i want to compare the two tables field by field. If some field does not match, i need to store a error message in some table specifying the field name which does not match. can anyone tell me how do i go about this????

4 REPLIES 4
Read only

matt
Active Contributor
0 Likes
702

Sort the tables. Check that they have the same number of entries. If they do, loop through one table into a workarea (wa1). Read a record with the SAME index (sy-tabix), in the other table into a workarea (wa2). Check each field of WA1 is the same as the fields in WA2. If these are field-symbol workareas, where you don't know the structure until runtime, then run through all the fields using

ASSIGN COMPONENT number OF STRUCTURE...

matt

Read only

Former Member
0 Likes
702

During the building of the dynamic internal tables, count the no. of fields of tables.

then

loop at <fs_t1> assigning to <fs_wa1>.
do v_var1 times.
assign component v_var1 of structure <fs_wa1> to <fs_f1>.
read table <fs_t2> assigning to <fs_wa2> with key field1 = <fs_wa>-field1.
if sy-subrc eq 0.
assign v_var1 of structure <fs_wa2> to <fs_f2>.
if <fs_f1> eq <fs_f2>.
continue.
else.
*move to the error internal table.
endif.
clear: <fs_f1>, <fs_f2>,<fs_wa2>.
enddo.
endloop.

Regards

Kannaiah

Read only

0 Likes
702

we cannot use key field1 = <fs_wa1>-field1.

Read only

0 Likes
702
describe table <fs_t2> lines v_line1.

loop at <fs_t1> assigning to <fs_wa1>.
do v_var1 times.
assign component v_var1 of structure <fs_wa1> to <fs_f1>.
if v_count LE v_line1.
read table <fs_t2> assigning to <fs_wa2> index v_count .
if sy-subrc eq 0.
assign v_var1 of structure <fs_wa2> to <fs_f2>.
if <fs_f1> eq <fs_f2>.
continue.
else.
*move to the error internal table.
endif.
endif.
clear: <fs_f1>, <fs_f2>,<fs_wa2>.
enddo.
v_count =  v_count + 1.
endloop.

Regards

Kannaiah