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 generic tables.

Former Member
0 Likes
608

Hi Guys,

I wanted to build a generic table comparison.

The general idea was to loop through one and read the other.


LOOP AT i_table1 ASSIGNING <line1>.
    READ TABLE i_table2 ASSIGNING <line2> INDEX sy-tabix.
      idx_field = 1.
      DO.
        UNASSIGN <field1>.
        UNASSIGN <field2>.
        ASSIGN COMPONENT idx_field OF STRUCTURE <line1> TO <field1>.
        ASSIGN COMPONENT idx_field OF STRUCTURE <line2> TO <field2>.
        IF <field1> IS ASSIGNED AND <field2> IS ASSIGNED.
          IF <field1> = <field2>.
         .....

but in order to make it generic the method parameter has to be of type ANY TABLE.

then i'm nit able to read the table by index.

Does anyone have a solution to compare to generic tables ?

Best Regards,

Rasmus

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
509

You can compare two tables like the next example:

if table1[] = table2[].

write 'ok'.

else.

write 'bad'.

endif.

Table1 and table2 can be field symbols

Hi Guys,

I wanted to build a generic table comparison.

The general idea was to loop through one and read the other.


LOOP AT i_table1 ASSIGNING <line1>.
    READ TABLE i_table2 ASSIGNING <line2> INDEX sy-tabix.
      idx_field = 1.
      DO.
        UNASSIGN <field1>.
        UNASSIGN <field2>.
        ASSIGN COMPONENT idx_field OF STRUCTURE <line1> TO <field1>.
        ASSIGN COMPONENT idx_field OF STRUCTURE <line2> TO <field2>.
        IF <field1> IS ASSIGNED AND <field2> IS ASSIGNED.
          IF <field1> = <field2>.
         .....

but in order to make it generic the method parameter has to be of type ANY TABLE.

then i'm nit able to read the table by index.

Does anyone have a solution to compare to generic tables ?

Best Regards,

Rasmus

2 REPLIES 2
Read only

Former Member
0 Likes
510

You can compare two tables like the next example:

if table1[] = table2[].

write 'ok'.

else.

write 'bad'.

endif.

Table1 and table2 can be field symbols

Read only

0 Likes
509

Hi Jorge,

Unfortunately there can be some minor differences due to some naming conventions.

So I have to check each field in order to determine if the difference is caused by these naming conventions.

Best Regards

Rasmus