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

please give optimized code very urgent

Former Member
0 Likes
296

DESCRIBE TABLE: TAB1 LINES L1,

TAB2 LINES L2.

IF L1 <> L2.

TAB_DIFFERENT = 'X'.

ELSE.

TAB_DIFFERENT = SPACE.

LOOP AT TAB1.

READ TABLE TAB2 INDEX SY-TABIX.

IF TAB1 <> TAB2.

TAB_DIFFERENT = 'X'. EXIT.

ENDIF .

ENDLOOP.

ENDIF.

IF TAB_DIFFERENT = SPACE.

" ...

ENDIF.

2 REPLIES 2
Read only

Former Member
0 Likes
276

Use this code:

IF TAB1[] NE TAB2[].
  TAB_DIFFERENT = 'X'.
ELSE.
  TAB_DIFFERENT = space.
ENDIF.

IF TAB_DIFFERENT = SPACE. 
" ... 
ENDIF.

Please mark points if the solution was useful.

Regards,

Manoj

Read only

Former Member
0 Likes
276

Find a unique key for itab2, here keyfield, and sort itab2 accordingly

sort itab2 by keyfield

loop at tab1 into wa1.

read table tab2 into wa2

with table key keyfield = wa1-keyfield.

index1 = sy-tabix.

  • entry not in itab2

if ( sy-subrc ne 0 ).

append wa1 to del_tab.

  • entry in itab2, update if different

else.

delete tab2 index index1.

if ( wa1-ctext ne wa2-ctext ).

append wa2 to upd_tab.

endif.

endif.

endloop.

  • in itab2 but not in itab1

ins_tab[] = tab2[].

This is the most general solution and performance is good:

del_tab contains lines which are in itab1 but not in itab2

upd_tab contains lines which are in both itab1 and itab2 but are different

ins_tab contains lines which are not in itab1 but in itab2

There are slightly faster solutions but this is one is fast enough, and much easier

to understand and to test.

Siegfried