Application Development 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: 

very very urjent comapring two tables delete extra records

Former Member
0 Kudos

hi experts,

this is very very urjent issue can u please provide logic.

1. i am having two tables kondd and kotd001.

2. here kondd table having 27 records and kotd001 having 16 records.

3. the issue is what ever extra records(27-16=6) 6 diff records should be delete

in the table kondd and deleted records(6) should be display in list.

4. deleted records download in application sever and presentation server

5. both tables should be equal records(16).

can u please solve this issue.

REPORT ZCONDITION.

tables: kondd,kotd001.

types: BEGIN OF T_KONDD, 27

KNUMH TYPE KONDD-KNUMH, "key field

SMATN TYPE KONDD-SMATN,

MEINS TYPE KONDD-MEINS,

SUGRD TYPE KONDD-SUGRD,

PSDSP TYPE KONDD-PSDSP,

LSTACS TYPE KONDD-LSTACS,

END OF T_KONDD.

types: BEGIN OF T_KOTD001, 16

KAPPL TYPE KOTD001-KAPPL,

KSCHL TYPE KOTD001-KSCHL,

MATWA TYPE KOTD001-MATWA,

DATBI TYPE KOTD001-DATBI,

DATAB TYPE KOTD001-DATAB,

KNUMH TYPE KOTD001-KNUMH,

END OF T_KOTD001.

2 REPLIES 2

Former Member
0 Kudos

loop at it1 into wa1.

read table it2 from wa with key field = wa-field.

if sy-subrc = 0.

append it3 to wa.

endif.

endloop.

kiran_k8
Active Contributor
0 Kudos

IF itab1[] = itab2[].

" Tables contents are the same

ELSE.

" Tables contents are different

ENDIF.

If they have different structure, loop one of the tables, and inside read the other, then compare field by field.

Or if don't need the contents (just comparing) you can do this, for example:

LOOP AT itab1 INTO waitab1.

READ TABLE itab2 WITH KEY field2 = waitab1-field2

field5 = waitab1-field5

TRANSPORTING NO FIELDS.

IF sy-subrc = 0.

" Record is on both tables (field2 and field5 are the fields in common for both tables).

ENDIF.

ENDLOOP.

As far as deletion is concerened you can follow the below given logic.

loop at itab.

v_tabix = sy-tabix.

read table itab2 with key <<<key field >> = itab-<<<key field>>

if sy-subrc eq 0

flag = 'X'.

modify itab.

endif.

endloop.

K.Kiran.